-
-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
call fnet_socket_shutdown() in SS_CLOSING cause FNET_ERR_NOTCONN #14
Comments
It is the same: [ENOTCONN] The s argument specifies a socket which is not connected. |
I have been traced some of the implementation of the Linux and FreeBSD. My observation is that the implementation of the
Futhermore, I think the FNET implementation at the moment is that the tcp_connection_state after receiving FIN from the remoted node will be in the state Honestly, I am not sure my finding is valid based on the other OSes' implementation, because there is no concrete document about this case. However, one of the problem I see is that the fnet' I am eager to know your opinion regarding this. |
So we can change the code to:
Are you OK with it? |
I think that is possible. I will test your suggestion and let you know the outcome within couple of days.On 17 Jul 2023, at 16:19, Andrej Butok ***@***.***> wrote:
So we can change the code to:
if(sk->state == SS_CLOSED)
{
_fnet_socket_set_error(sk, FNET_ERR_NOTCONN);
return FNET_ERR;
}
else
Are you OK with it?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
After a few testings, I can confirm the change in the condition Do you want me to create the Pull Request or you can update it when you have a chance? Here is the snippet of code I wrote to do the sanity test the modification. I put here just for the sake of tracking the discussion. ...
// Check if received data is "exit"
if ( buffer[0] == 'e' &&
buffer[1] == 'x'&&
buffer[2] == 'i'&&
buffer[3] == 't') {
// Print shutdown message
char shutdown_msg[] = "Received 'exit' command. Shutting down writing.\n";
fnet_socket_send(context->sockfd, shutdown_msg, sizeof(shutdown_msg) - 1,0);
fnet_socket_getopt(context->sockfd,SOL_SOCKET,SO_STATE,(void*)&test_socket_state,(fnet_size_t*)&len);
// Shutdown writing
test_fnet_return = fnet_socket_shutdown(context->sockfd, SD_WRITE);
context->state = ETH_CLIENT_CLOSING;
}
... The above code check the state of the socket via the variable The behaviour before the modification:
The behaviour after the modification:
|
Yes, if you can. It will be quicker. |
Merged. |
After thought, though it is irrelevant, my "fix" for the I have investigated a bit and it seem Henri de Veer from your the sourceforge thread has addressed it correctly. I will make another PR to fix that, are you fine with that? Really sorry for my overlooking in that function. |
ok |
Assuming the MCU running FNET as a server, after successful connection with the client via TCP, then at some point, the client indicates to shutdown the connection by sending some messages to prepare to tear down the connection, then call API
shutdown( clientSock, SHUT_WR)
. From the FNET server, as the client has not closed yet, calling tofnet_socket_shutdown()
shall not return error with the errnoFNET_ERR_NOTCONN
.How to reproduce:
Server side (running FNET)
server_sock = fnet_socket(AF_INET, SOCK_STREAM, 0)
;fnet_socket_bind(server_sock, IP_and_port, sizeof(IP_and_port)
;fnet_socket_listen()
;client_sock = fnet_socket_accetp()
;fnet_socket_shutdown(client_sock, SD_WRITE);
, at this point we get the return value to be (-1) and the FNET_ERR_NUMBER isFNET_ERR_NOTCONN
.Client side (on PC):
shutdown(clien_socket, SHUT_WR);
The problem happens when the server receives the FIN packet, it changes the socket state
sk->state = SS_CLOSING
. And tracing the problem from the fnet_socket_shutdown, it eventually called to_fnet_tcp_shutdown
, the problem seem to be the following code snippet:In my opinion, the SS_CLOSING meaning that the connection is still not reach the CLOSED state yet, thus, considering it is the error is not the expected behavior. In the normal case, it shall be able to run the another else branch and sending out the FIN packet and process, before we actually call the
close
function. My proposal, if that is the valid finding, is changing that if condition to:I would like to know your opinion on this finding, as it seems the behavior is different from the document from this link https://man.freebsd.org/cgi/man.cgi?query=shutdown&sektion=2
The text was updated successfully, but these errors were encountered: