lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] How to force-close a netconn from the server side?


From: Freddie Chopin
Subject: [lwip-users] How to force-close a netconn from the server side?
Date: Wed, 25 Jan 2017 17:09:48 +0100

Hello!

Currently in a project with lwIP I'm facing an issue with closing
netconns and I failed to find a solution by myself, so I'm writing here
in hope for some guidance.

Let's say that there are 5 listening netconns, each bound to a
different port, let's say 1001-1005. I'm accepting 5 different client
connections and this works perfectly fine. This is done with a typical
sequence:
listenNetconn = netconn_new();
netconn_bind(listenNetconn, IP_ADDR_ANY, somePort);
netconn_listen(listenNetconn);
clientNetconn = netconn_accept(listenNetconn);

However this application has a requirement, that there must be an
option to immediately shut down all or some of the connections. So
let's say that the operator wishes to immediately close the 3
connections at ports 1001-1003. This is done by:

netconn_delete(listenNetconn);
netconn_delete(clientNetconn);

This also (probably) works - the data flow stops and no new connections
are accepted.

However when the operator decides to resume communication at these
ports, any further attempt to do "netconn_bind(listenNetconn,
IP_ADDR_ANY, somePort);" fails, because there's an active PCB (from one
one the force-closed client connections) on that port, which is checked
in tcp_bind() in the loop below "/* Check if the address already is in
use (on all lists) */" comment. This active PCB is in FIN_WAIT_1 state.

>From my search of the internet and the archives of this list I know
that this is intended behaviour, because the client and server are
still trying to gracefully close the channel. However there does not
seem to be any way to actually "fix" the system once it reaches that
state - it does not matter if I close the client software on the PC or
not, as this active PCB stays there for "very long". I've tried setting
"linger" to 0 for the client netconns before deleting them, but this
does not solve anything. Is there any other way than direct messing
with the tcp_pcb to set SOF_REUSEADDR in the so_options field? Maybe
I'm doing something wrong here (except force-closing the client
connections (; )?

Any help is much appreciated! Thanks in advance!

Regards,
FCh



reply via email to

[Prev in Thread] Current Thread [Next in Thread]