|
From: Stephen S. <rad...@gm...> - 2012-07-11 21:24:20
|
Hi Camille, Sorry, I have been meaning to get to the TCP stuff for over two months now. I didn't do a release in May as I said I would, and now it's July! On Mon, Jun 4, 2012 at 6:07 AM, Camille Troillard <ca...@os...> wrote: > Hello Stephen, > > I am resurrecting an old discussion. > To refresh your memory, the problem was the following: > > 1- using liblo, TCP client sends data to a TCP server. > 2- client stops sending data. > 3- the server is closed. > 4- now we try to open the server again on the same port. > 5- -> results in "error port in use" and the server can not be open anymore. > > > The server can be opened again only if we wait enough (about 1 minute), or this scenario happens: > > 1- using liblo, TCP client sends data to a TCP server. > 2- client stops sending data. > 3- the server is closed. > 3b- the client sends a message to the closed server -> result in an expected error. > 4- now we try to open the server again on the same port. > 5- -> the server is opened again. > > > A friend gave me what looks like a good solution: > Set the SO_REUSEADDR flag on the server socket. > So far, this works well for me and fixes a behavior I considered as a bug since a long time. To me these symptoms seem to indicate that the server is not properly closing the port, which is surprising because afaik there are close() and shutdown() calls in all the right places, but perhaps there is something missing. So I think the correct fix would be to make sure that errors are detected and handled properly, and the the shutdown procedure is correct. However, in the meantime I don't see any reason not to set this flag. Just wanted to check that it doesn't do weird things when you start multiple servers on the same port, but so-far-so-good. I modified example_server.c to use LO_TCP, verified that SO_REUSEADDR is set, and it still gives me "cannot find free port" when it is run twice. Anyways, patch applied. Steve |