To fix the bind error, in ThreadedAppServer.__init__:
Change:
self.mainsocket = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
To:
self.mainsocket = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
self.mainsocket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
I was under the impression that SO_REUSEADDR was not risky to use but
after poking around some more I found that for servers binding to a well
known port, it should be used. The following post also explains why
webkit owns the connections instead of the adaptor: it just depends
which side of the connection closes first.
Jeff
PS: the two lines:
self.threadCount=0
self.threadUseCounter=[]
should be moved above the exception handler for the bind or the shutdown
call raises an exception.
The following post is from
http://groups.google.com/groups?q=time_wait+bind+foreign&hl=en&rnum=3&se
lm=87sodsgjzz.fsf%40erlenstar.demon.co.uk:
What happens is this. When you close a TCP connection cleanly, at
least one end of the connection (the one that closes first) will
remain in the TIME_WAIT state for a couple of minutes after the
close. This is part of the mechanism to ensure a fully reliable close
(it ensures that a sensible response is sent to any stray leftover
segments that may have been wandering around the network).
Unix systems by default will not let you bind() to an address/port
combination that has *any* TCBs referencing it (in any state,
including TIME_WAIT); thus until the TIME_WAIT state is ended from the
previous incarnation of the program, your attempt to bind to the port
fails. This restriction is too strict for server sockets on fixed
(well-known) ports, hence there is a mechanism to bypass it (by
setting SO_REUSEADDR) and allow you to bind() to an address/port
combination that is already in use by *connected* TCBs (ones which
have a specified foreign address/port). This is not in any way
incorrect behaviour, since TCP connections are identified by *both*
the local and foreign address/port pairs.
In short: if you are writing a server program that binds to a fixed
port number, always set SO_REUSEADDR before the bind() call. There are
no known exceptions to this rule.
_______________________________________________
Webware-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-devel