rbos36 wrote on Wednesday, January 17, 2018:
The documentation for FreeRTOS_send() (from the +TCP stack) mentions that it returns -pdFREERTOS_ERRNO_ENOTCONN when the receiving party has closed its side of the connection. However, in practice I do not see this behavior; I only see send() returning 0, which as far as I know indicates that there is no space in the send buffer.
Are we overlooking something?
I ended up coding a special case to detect closing of the client socket, like this:
Status socketSendAll(uint8_t *buffer, size_t bufferSize)
{
Status result = STATUS_OK;
uint8_t* bytes = buffer;
size_t remaining = bufferSize;
BaseType_t sent;
do {
sent = FreeRTOS_send(socket, (const void*)bytes, remaining, 0);
bytes += sent;
remaining -= sent;
} while (remaining > 0 && sent > 0);
/**
* TODO RBO I have seen situations where sent = 0 and remaining > 0. This occurred
* when capturing data with the Python client, after closing the client. This should cause
* the socket to close in the <product> as well, and I would expect send() to return a negative
* value (error code). However, this does not seem the case at the moment, so handle this case
* separately here. */
if (sent == 0 && remaining > 0) {
result = SAMPLE_TRANSPORT_SEND_FAILED;
}
/* Further error handling omitted */
}