10 years, 3 months ago.

cc3000 TCPSocketServer::accept timeout

In the new cc3000 library, the accept function of TCPSocketServer is set to block by default, but appears to have a very short timeout, so it looks like it has immediately failed.

It would be great if accept could be changed to block for longer or (preferably) indefinately

Also, returning a different error code for a timeout would be useful.

Regards

James

Hello James Masterman,

can you set sockopt to blocking? Report here the result.

int32_t setsockopt(int32_t sd, int32_t level, int32_t optname, const void *optval, socklen_t optlen);

SOCK_NONBLOCK (optname). set socket non-blocking mode is on or off. SOCK_ON or SOCK_OFF (optval)

Regards,
0xc0170

posted by Martin Kojtal 09 Dec 2013

Looks like I was wrong on this one. I set the socketserver to blocking and it works correctly!

During this investigation, I found one other minor issue with TCPSocketConnection::receive

I find that if a TCP client connects and then the connection drops out on the remote end for whatever reason (battery failure, device switched off, network issue etc) the socket does not detected the dropped connection if it's set to be non blocking. If I set the TCPSocketConnection to block, it works fine and detects the dropped connection. The issue is that in the receive function, when the socket is non-blocking, the function waits for data to become readable as below. However on a dropped connection of course no data ever appears.

if (!_blocking) { TimeInterval timeout(_timeout); if (wait_readable(timeout) != 0) return -2; }

The problem is the that the underlying socket is not checked so it will never know that the connection is dropped. When the socket is set to blocking, the timeout code is not entered and the socket is directly polled

int n = _cc3000_module->_socket.recv(_sock_fd, data, length, 0); if (n >= 0) { _is_connected = 1; } else { _is_connected = 0; }

At which point the dropped connection is detected and all is good.

The function needs a way to check for dropped connections for non-blocking sockets.

posted by James Masterman 10 Dec 2013

Hello,

probably same as issue which was reported a while ago. Here's a link: http://mbed.org/users/Kojto/code/cc3000_hostdriver_mbedsocket/issues/3

There is an array _closed_sockets, which should be checked. If you have time, can fix this one, would be appreciated.

Regards,
0xc0170

posted by Martin Kojtal 10 Dec 2013
Be the first to answer this question.