I am using the RTCS stack for a Ethernet server application. The TCP & UDP sockets are working fine.
When the client application closes the communication from its end, it sends out FIN,ACK. Here the RTCS is closing the socket properly by sending out the response with RST flag set.
However when i close the client application without closing the communication, the client application sends out the request with RST,ACK flags set. In my code, the following condition is met
(RTCS_get_errno() == RTCSERR_SOCK_ESHUTDOWN)
{
closesocket(sock);
}
However, the RTCS dont send out the RST response to acknowledge the socket close. Is this expected or i am supposed to call some other api instead of closesocket()?
The SO_LINGER socket option indicates how the socket is to be shut down: either gracefully or with an abort operation (TCP reset). If the socket is to be shut down gracefully, RTCS tries to deliver all the data that is in its send buffer for the socket. If you shutting down with an abort operation, RTCS immediately discards the socket and the socket's internal send and receive buffers; The remote endpoint frees its socket immediately after it sends all the data that is in its send buffer.
Please check the MQX_RTCS_User_Guide.pdf for more details. P110, closesocket()
Please check the following code to use SO_LINGER socket options:
struct linger l_options;
/* Set linger options for RST flag sending. */
l_options.l_onoff = 1;
l_options.l_linger_ms = 0;
setsockopt(sock, SOL_SOCKET, SO_LINGER, &l_options, sizeof(l_options));
closesocket(sock);
Note: If this post is helpful, please mark correct or helpful, thank you
Regards
Daniel