Re: [lwip-users] Bind fails after previous server-initiated connection close

2017-06-09 Thread Joel Cunningham
Hi,

This is normal BSD semantics of a TCP listener, use SO_REUSEADDR before calling 
bind to avoid the issue


Joel

> On Jun 8, 2017, at 4:18 PM, Ignacio García Pérez  wrote:
> 
> Hi All,
> 
> I'm writing a simple FTP server that needs to be started up and shut down 
> with relatively high frequency (say once per minute), so each time I must 
> create the listening PCB, bind, listen, accept, etc. The problem is that when 
> I close a client connection the PCB goes into the TIME-WAIT state and the 
> next bind operation will fail with ERR_USE.
> 
> Looking at the code I see that all TIME-WAIT PCB are kept in a list and this 
> list is checked for the requested port in the tcp_bind() function.
> 
> Of course eventually the PCB is purged (after 2 * TCP_MSL = 120s by default), 
> but  that does not solve the problem in my scenario (which I admit is 
> somewhat exotic).
> 
> Question:
> 
> 1- Is this behaviour expected?
> 
> 2- Is there any workaround?
> 
> If the purpose of keeping the PCB in TIME-WAIT is to prevent new connections 
> to/from the same host:port to be created, it doesn't make sense to check when 
> calling tcp_bind(), it would make more sense to check calling tcp_connect() 
> or when an incoming connection is initiated.
> ___
> lwip-users mailing list
> lwip-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/lwip-users


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Bind fails after previous server-initiated connection close

2017-06-09 Thread Simon Goldschmidt
Ignacio García Pérez wrote:
> I'm writing a simple FTP server that needs to be started up and shut down 
> with relatively high frequency (say once per minute)

That's a strange application scenario. And the result of this is what you are 
seeing.

> Question:
> 1- Is this behaviour expected?

Yes! See Sergio's answer.
 
> 2- Is there any workaround?

Yes. You are not the first having this problem. There's SO_REUSE (not 
lwIP-specific, by the way), but if you use it, you should know what you're 
doing!

Simon

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Bind fails after previous server-initiated connection close

2017-06-09 Thread Sergio R. Caprile
According to major communications texts authors, due to parallel paths 
and some esoteric magic, some data might be in transit when you close a 
TCP connection. IIRC it is mandatory that it remains that way after closure.

There is a thread on this list where Simon answered (sort of) your question

If you need a faster response, you need to provide more pcbs, look at 
the httpd server, for example, which serves lots of short connections.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users