wip
Fork of Socket by
Diff: TCPSocketConnection.cpp
- Revision:
- 6:cd2e5559786d
- Parent:
- 5:300e7ad2dc1d
- Child:
- 10:d24738f4ef99
diff -r 300e7ad2dc1d -r cd2e5559786d TCPSocketConnection.cpp --- a/TCPSocketConnection.cpp Thu Jul 26 15:07:32 2012 +0000 +++ b/TCPSocketConnection.cpp Fri Jul 27 13:58:53 2012 +0000 @@ -40,12 +40,12 @@ return 0; } -int TCPSocketConnection::send(char* data, int length, int timeout) { +int TCPSocketConnection::send(char* data, int length, int timeout_ms) { if ((_sock_fd < 0) || _closedByRemoteHost) return -1; - set_timeout(timeout); - if (wait_writable() != 0) + TimeInterval timeout(timeout_ms); + if (wait_writable(timeout) != 0) return -1; int n = lwip_send(_sock_fd, data, length, 0); @@ -55,15 +55,15 @@ } // -1 if unsuccessful, else number of bytes written -int TCPSocketConnection::send_all(char* data, int length, int timeout) { +int TCPSocketConnection::send_all(char* data, int length, int timeout_ms) { if ((_sock_fd < 0) || _closedByRemoteHost) return -1; size_t writtenLen = 0; - set_timeout(timeout); + TimeInterval timeout(timeout_ms); while (writtenLen < length) { // Wait for socket to be writeable - if (wait_writable() != 0) + if (wait_writable(timeout) != 0) return writtenLen; //Timeout -- FIXME should we return -1 or writtenLength ? int ret = lwip_send(_sock_fd, data + writtenLen, length - writtenLen, 0); @@ -81,12 +81,12 @@ return writtenLen; } -int TCPSocketConnection::receive(char* data, int length, int timeout) { +int TCPSocketConnection::receive(char* data, int length, int timeout_ms) { if ((_sock_fd < 0) || _closedByRemoteHost) return -1; - set_timeout(timeout); - if (wait_readable() != 0) + TimeInterval timeout(timeout_ms); + if (wait_readable(timeout) != 0) return -1; int n = lwip_recv(_sock_fd, data, length, 0); @@ -96,15 +96,15 @@ } // -1 if unsuccessful, else number of bytes received -int TCPSocketConnection::receive_all(char* data, int length, int timeout) { +int TCPSocketConnection::receive_all(char* data, int length, int timeout_ms) { if ((_sock_fd < 0) || _closedByRemoteHost) return -1; size_t readLen = 0; - set_timeout(timeout); + TimeInterval timeout(timeout_ms); while (readLen < length) { //Wait for socket to be readable - if (wait_readable() != 0) + if (wait_readable(timeout) != 0) return readLen; //Timeout -- FIXME should we return -1 or writtenLength ? int ret = lwip_recv(_sock_fd, data + readLen, length - readLen, 0);