lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] Problem re-opening listening pbc


From: Keith Rubow
Subject: Re: [lwip-users] Problem re-opening listening pbc
Date: Thu, 10 May 2018 11:24:50 -0700
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

My problem with limiting the number of connections on a port has taken a turn for the worse. I am trying to implement modbus over TCP on port 502. I must allow up to 3 concurrent connections to port 502, but no more. My trick of closing the listening pcb when I have reached my limit of 3 connections does not work. The problem is that once I have accepted the 3rd connection I can close the listening pcb. This causes subsequent connection attempt to be refused (as desired). However, once any one of the 3 connections is closed I need to re-open the listening pbc so another connection can be accepted. But I cannot bind to port 502 if ANY previous connection is still open. Waiting for all connections to close before re-opening the listing pbc is not an option. A connection could be up for days.

I could call tcp_abort() in my accept callback once the connection limit has been exceeded, but this does not cause the connection to be rejected. The client seed the connection accepted, and then immediately closed. I would prefer to see new connection attempts rejected once I have reached my connection limit.

Is there any way to achieve a limit on the number of connections allowed on a given port (with further connection attempts rejected)? As stated earlier, NO_SYS=1, raw callback API.

Also, why does lwip not allow me to open a listening pcb on a port if there are current open connections to that port (even though there is no current LISTENING pbc on the port)?

Any help is appreciated.

Keith Rubow

On 5/9/2018 1:11 PM, Keith Rubow wrote:
I'm using LWIP for the first time (2.0.3, NO_SYS=1, callback API). Mostly things are going well. But I have an issue with allowing only a single TCP connection to a port. I open a listening pcb with tcp_new(), tcp_bind(), tcp_listen() and set an accept callback. In the accept callback I set up a receive callback, and I use tcp_close() to close the listening pcb. This causes any further connection attempts on the port to be refused. This works great.

However, the problem is when the connection I accepted is closed. My receive callback is called with p=NULL, so I then remove all the callbacks and close the active connection with tcp_close(). Then I re-open the listening pcb with tcp_new(), tcp_bind(), and tcp_listen(). HOWEVER, the tcp_bind() fails with ERR_USE, presumably because the pcb for the active connection is not fully closed yet, making the port still in use.

I found I can "fix" the problem by closing the active connection with tcp_abort() instead of tcp_close(), but this seems kind of wrong. If I knew when the pcb for the active connection was really fully closed, I could open the listening pcb then. But I don't see any way to tell when the close is finished. There is no callback for it, and I am not permitted to access the pcb after calling tcp_close().

So how can I re-open a listening pcb on the port after a connection is closed?

Keith Rubow

_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users





reply via email to

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