unsigned char fnGetTCP_state(
USOCKET TCP_socket);
TCPSocket is the number of the TCP socket whose present state is to be returned.
The routine is used to request the state of a TCP socket. The return value is the present TCP socket state or
an error
TCP_STATE_BAD_SOCKET if the socket doesn't exist:
- TCP_STATE_FREE - potential TCP socket space is free
- TCP_STATE_RESERVED - TCP socket has been obtained
- TCP_STATE_CLOSED - TCP socket has been bound and is in closed state
- TCP_STATE_LISTEN - server has been set to the listening state and is waiting for a SYN reception (incoming connections)
- TCP_STATE_SYN_RCVD - SYN has been received (either to the SYN we sent or from an incomming connection)
- TCP_STATE_SYN_SENT - SYN packet sent as an attempt to establish a connection
- TCP_STATE_FIN_WAIT_1 - application wants to close, we have sent FIN
- TCP_STATE_FIN_WAIT_2 - ACK received to our FIN, wait for FIN from partner
- TCP_STATE_CLOSING - doing simultaneous close; FIN received and ACK sent, waiting for final ACK to our FIN
- TCP_STATE_CLOSE_WAIT - passive close. We have received a FIN and sent an ACK to it. We are waiting for our application to close
- TCP_STATE_LAST_ACK - passive close. Our application has terminated and we have sent FIN. Waiting for final ACK to our FIN
- TCP_STATE_TIME_WAIT - active close terminated. Wait 2MSL time before allowing new connection
- TCP_STATE_ESTABLISHED - connection established - in data transfer state
- TCP_STATE_BAD_SOCKET - this state doesn't exist but this is returned by fnGetTCP_state if the socket is invalid
Note that the state values has been carefully designed to allow efficient checking of multiple state. For example:
if (!(ptr_TCP->ucTCP_state & (TCP_STATE_RESERVED | TCP_STATE_LISTEN | TCP_STATE_CLOSED))) {}
checks for states which would not allow a new connection to be achieved by checking several individual bits.
Example
if (fnGetTCP_state(http_socket) & TCP_STATE_LISTEN) {
fnDebugMsg("HTTP socket is in listening state\r\n");
}
See the following forum thread for additional details about working with TCP sockets:
µTasker forum TCP discussion.
Related functions
fnGetTCP_Socket();
fnReleaseTCP_Socket();
fnTCP_Listen();
fnTCP_Activity();
fnTCP_Connect();
fnTCP_close();
Please use the
µTasker forum to ask specific questions.