Hello, I'm writing a simple echo server with a CC3000 and am running into difficulty detecting when a connection is closed. Here's what I've tried:
- Be notified by select() that the closed socket is available for reading, then getting 0 bytes back from recv(). I.e. normal BSD socket behavior. Unfortunately it looks like TI's firmware explicitly does not support this behavior, at least according to the answer here: http://e2e.ti.com/support/low_power_rf/f/851/t/200366.aspx
- Be notified by select() that the closed socket is in an exception state through the exceptsds result. The TI docs claim a closed socket will be in an error state, but I can't see closed sockets getting returned from select in the exceptsds result. This thread seems to corroborate the behavior I see: http://e2e.ti.com/support/low_power_rf/f/851/t/259746.aspx
- Try sending 0 bytes of data and catching the error that the socket is closed. This is suggested as a workaround in the above thread, but when I try to call send with a size of zero bytes my MCU appears to be resetting itself (not sure what's going on, maybe some undefined behavior with the CC3000?)
I wanted to check, what's the right way to detect that a TCP connection has been closed? Is actually sending data with send (as opposed to faking it with a 0 byte size send) and detecting an error the only way?