What’s the difference between TCP’s close and TCP’s abort? Following is an example:
..//init the socket FD
while(1)
{
switch(socket_state)
{
case 0:
if(0 != FD)
{
tcp_connect(FD,rem_ip, 502, 0);
socket_state = 1;
break;
}
case 2:
if(TRUE == wait_ack)
{
return;
}
..//sending data
wait_ack = TRUE;
break;
case 3:
{
if(0 != FD)
{
tcp_close(FD); //or tcp_abort(FD);
tcp_release_socket(FD);
soc_state = 0;
}
}
break;
}
}
tcp_callback:
U16 Listener(U8 socket,U8 event,U8* ptr,U16 par)
switch(event)
{
case TCP_EVT_CONNECT:
soc_state = 2;
break;
case TCP_EVT_ACK:
wait_ack = __FALSE;
break;
case TCP_EVT_ABORT:
soc_state = 3;
break;
}
return (1);
Now, when I shut the server down, my client will receive a TCP_EVT_ABORT message, and set soc_state = 3. In while(1) loop, switch sees this and goes into case 3. Do I want it to close, or abort? In the next loop iteration, I go back to state 0. Why is the file descriptor still not 0?
How can I use abort or close mechnism correctly?
A little hard to understand,When you use
tcp_get_socket,then the socket is allocated and its state isTCP_STATE_CLOSED.After that,usingtcp_connectto connect remote server.Its state will change toTCP_STATE_SYN_REC.When connection is established,state becomeTCP_STATE_CONNECT.When server side is shut down,Client side will receive EVENT :TCP_EVT_ABORT. I close current socket usingtcp_release_socket. Also when data is sent completed,using this function close socket.Next time ,we should invoketcp_get_socketbeforetcp_connectwith the old socket. For short,every connection,everytcp_get_socket.