Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PicoTCP by
Diff: Socket/TCPSocketConnection.cpp
- Revision:
- 39:8d4d653d94bd
- Parent:
- 37:bdf736327c71
- Child:
- 44:ffd9a11d4f95
--- a/Socket/TCPSocketConnection.cpp Fri Jul 05 12:38:29 2013 +0000
+++ b/Socket/TCPSocketConnection.cpp Thu Jul 11 10:17:25 2013 +0000
@@ -64,13 +64,21 @@
int TCPSocketConnection::send(char* data, int length) {
int ret;
- if ((_ep < 0) || !_is_connected)
+ if ((_ep == NULL) || !_is_connected)
return -1;
+ if(is_writable())
+ {
+ ret = picotcp_write(_ep, data, length);
+ if(ret < length)
+ _ep->revents &= (~PICO_SOCK_EV_WR);
+ if(ret) // data was read or error was reported
+ return ret;
+ }
+
TimeInterval timeout(!_blocking ? _timeout : osWaitForever);
if (wait_writable(timeout) != 0)
{
- printf("Failed\n");
return -1;
}
@@ -84,34 +92,26 @@
// -1 if unsuccessful, else number of bytes written
int TCPSocketConnection::send_all(char* data, int length) {
- int ret;
- if ((_ep < 0) || !_is_connected)
- return -1;
-
-
- TimeInterval timeout(!_blocking? _timeout : osWaitForever);
- // Wait for socket to be writeable
- if (wait_writable(timeout) != 0) {
- return 0;
- }
- ret = picotcp_write(_ep, data, length);
- if (ret < length) {
- _ep->revents &= (~PICO_SOCK_EV_WR);
- //printf("Short write\n");
- }
- return ret;
+ return send(data,length);
}
int TCPSocketConnection::receive(char* data, int length) {
int ret;
- if ((_ep < 0) || !_is_connected)
+ if ((_ep == NULL) || !_is_connected)
return -1;
+ if(is_readable())
+ {
+ ret = picotcp_read(_ep, data, length);
+ if(ret<length)
+ _ep->revents &= (~PICO_SOCK_EV_RD);
+ if(ret) // data was read or error was reported
+ return ret;
+ }
TimeInterval timeout(!_blocking ? _timeout : osWaitForever);
if (wait_readable(timeout) != 0)
{
- printf("Failed receiving\n");
return -1;
}
