The tcp_close function initiates the procedure to close the
TCP connection. It might take some time to close the connection. The
argument socket specifies the handle of the socket whose
connection is to be closed.
TCPnet calls the listener callback function only, when a
remote peer has closed the connection. If the socket closing
is initiated locally by calling tcp_close, the callback
function is not called.
When a socket type is TCP_TYPE_SERVER or
TCP_TYPE_CLIENT_SERVER, the socket does not close after calling
tcp_close. The active connection is closed, and the socket
transits to TCP_STATE_LISTEN. In this state, the socket is still able
to accept incoming connections. To close the TCP_TYPE_SERVER socket,
the function tcp_close needs to be called twice.
The tcp_close function is in the RL-TCPnet library. The
prototype is defined in rtl.h.
note
After calling tcp_close the socket still remains
allocated until you release it.
Return Value
The tcp_close function returns __TRUE if the connection
closing procedure has been started successfully. Otherwise, the
function returns __FALSE.
#include <rtl.h>
void disconnect_tcp (U8 tcp_soc) {
..
/* This TCP connection is no longer needed */
tcp_close (tcp_soc);
/* Release TCP Socket in a polling function */
}
void poll_socket (U8 tcp_soc) {
int state;
state = tcp_get_state (tcp_soc);
if (state > TCP_STATE_LISTEN) {
/* Closing procedure is on-going */
return;
}
if (state == TCP_STATE_LISTEN) [
/* Socket has TCP_TYPE_SERVER attribute */
/* needs additional close request. */
tcp_close (tcp_soc);
}
/* A socket is in TCP_STATE_CLOSED state now. */
tcp_release_socket (tcp_soc);
}
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.