Ping... this question seemed to be waiting on our mailing list for several days:

On Tue, Jun 30, 2020 at 4:58 AM Reto Gähwiler <gret.hexa...@gmail.com> wrote:
> I am facing the following problem working with nuttx and ethernet
> connections. A TCP socket is setup as blocking and connected to the server.
> The connection is handled in one thread which hangs in the recv call and
> processes the data if some arrives. In case of an error the connection is
> closed.
> Now, if a close() call on that particular TCP connection is called from a
> different thread, it terminates the connection and the recv() fails and
> breaks free.
> If we now connect to a new IP, it first seems to be fine but shortly after
> the whole network disappears. No more icmp responses (therefore no ping)
> and all other opened connections in different threads are not reachable
> anymore. Besides, any of the still opened connections starts to consume all
> cpu time. Looking into it with the debugger attached it can be seen,
> that in the net/devif/devif_callback.c the for-loop looking for the
> callback in the device event list is cycling without an end.

(snip)

> I was wondering if anyone else ran into the issue of calling close on a
> socket from a different thread as the recv/send is handled on and that the
> following connection kills the entire ethernet? Please let me know if you
> know a fix for blocking sockets or it would be better to go with
> non-blocking and work with select/poll instead.

Hi Reto,

Have you considered trying to put all the handling into a single
thread and using some sort of inter-thread messaging to request that
thread to close the connection when no longer needed?

I don't know the answer to calling close() from another thread because
I have always written my networking code to manage a socket by a
single thread, where all operations on the socket occur in that same
thread.

If your concern is blocking while waiting to recv() or recvfrom(), I
use select() to check whether any received data is waiting, usually
with a timeout so that the thread can do other things while it waits
for data.

Hopefully someone else can chime in about your specific question.

Nathan

Reply via email to