wip
Fork of Socket by
Diff: TCPSocketConnection.cpp
- Revision:
- 10:d24738f4ef99
- Parent:
- 6:cd2e5559786d
- Child:
- 11:3d83c348fb8b
diff -r f972715add36 -r d24738f4ef99 TCPSocketConnection.cpp --- a/TCPSocketConnection.cpp Fri Jul 27 15:56:20 2012 +0000 +++ b/TCPSocketConnection.cpp Tue Jul 31 11:50:55 2012 +0000 @@ -40,13 +40,15 @@ return 0; } -int TCPSocketConnection::send(char* data, int length, int timeout_ms) { +int TCPSocketConnection::send(char* data, int length) { if ((_sock_fd < 0) || _closedByRemoteHost) return -1; - TimeInterval timeout(timeout_ms); - if (wait_writable(timeout) != 0) - return -1; + if (!_blocking) { + TimeInterval timeout(_timeout); + if (wait_writable(timeout) != 0) + return -1; + } int n = lwip_send(_sock_fd, data, length, 0); _closedByRemoteHost = (n == 0); @@ -55,16 +57,19 @@ } // -1 if unsuccessful, else number of bytes written -int TCPSocketConnection::send_all(char* data, int length, int timeout_ms) { +int TCPSocketConnection::send_all(char* data, int length) { if ((_sock_fd < 0) || _closedByRemoteHost) return -1; size_t writtenLen = 0; - TimeInterval timeout(timeout_ms); + + TimeInterval timeout(_timeout); while (writtenLen < length) { - // Wait for socket to be writeable - if (wait_writable(timeout) != 0) - return writtenLen; //Timeout -- FIXME should we return -1 or writtenLength ? + if (!_blocking) { + // Wait for socket to be writeable + 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); if (ret > 0) { @@ -81,13 +86,15 @@ return writtenLen; } -int TCPSocketConnection::receive(char* data, int length, int timeout_ms) { +int TCPSocketConnection::receive(char* data, int length) { if ((_sock_fd < 0) || _closedByRemoteHost) return -1; - TimeInterval timeout(timeout_ms); - if (wait_readable(timeout) != 0) - return -1; + if (!_blocking) { + TimeInterval timeout(_timeout); + if (wait_readable(timeout) != 0) + return -1; + } int n = lwip_recv(_sock_fd, data, length, 0); _closedByRemoteHost = (n == 0); @@ -96,16 +103,18 @@ } // -1 if unsuccessful, else number of bytes received -int TCPSocketConnection::receive_all(char* data, int length, int timeout_ms) { +int TCPSocketConnection::receive_all(char* data, int length) { if ((_sock_fd < 0) || _closedByRemoteHost) return -1; size_t readLen = 0; - TimeInterval timeout(timeout_ms); + TimeInterval timeout(_timeout); while (readLen < length) { - //Wait for socket to be readable - if (wait_readable(timeout) != 0) - return readLen; //Timeout -- FIXME should we return -1 or writtenLength ? + if (!_blocking) { + //Wait for socket to be readable + 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); if (ret > 0) {