From API point of view, we try to follow POSIX as close as possible.
In POSIX: recv() http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html
"Upon successful completion, recv() shall return the length of the message in bytes. If no messages are available to be received and the peer has performed an orderly shutdown, recv() shall return 0. Otherwise, -1 shall be returned and errno set to indicate the error."
So you need to return zero, at least for first recv() call, because closing a TCP socket it considered normal operation, so you cannot throw an error there.
Also, note that it has to be proper connection closing.. RESET flag, or lost connection are allowed to return error, but cleanly shutdown should be OK(0) for the first recv() call.
Status
TCP test is FAIL for both DISCO F413 and L475 :
Console log:
[1536618580.93][CONN][RXD] >>> Running case #14: 'TCPSOCKET_ENDPOINT_CLOSE'... [1536618580.98][CONN][INF] found KV pair in stream: {{__testcase_start;TCPSOCKET_ENDPOINT_CLOSE}}, queued... [1536618581.56][CONN][RXD] :75::FAIL
Information from Seppo:
https://tools.ietf.org/html/rfc867 "The service closes the connection after sending the quote."
So yes, it is supposed to close.
From API point of view, we try to follow POSIX as close as possible. In POSIX: recv() http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html "Upon successful completion, recv() shall return the length of the message in bytes. If no messages are available to be received and the peer has performed an orderly shutdown, recv() shall return 0. Otherwise, -1 shall be returned and errno set to indicate the error."
In Mbed OS TCPSocket::recv(): https://os.mbed.com/docs/v5.9/mbed-os-api-doxy/class_t_c_p_socket.html#ac5f7d7ea02ce27bde53f6c7da0b2b75a "Returns: Number of received bytes on success, negative error code on failure. If no data is available to be received and the peer has performed an orderly shutdown, recv() returns 0."
So you need to return zero, at least for first recv() call, because closing a TCP socket it considered normal operation, so you cannot throw an error there.
Also, note that it has to be proper connection closing.. RESET flag, or lost connection are allowed to return error, but cleanly shutdown should be OK(0) for the first recv() call.