closing a server socket
simon place
simon_place at whsmithnet.co.uk
Tue Oct 14 17:25:43 EDT 2003
Peter Hansen wrote:
> simon place wrote:
>
>>Spent some very frustrating hours recoding to find a way of closing a server
>>socket, i'd not thought it would be any problem,
>>
>>however, after complete failure and as a last resort, i looked at the python
>>wrapper module for sockets, and found that the close command doesn't actually
>>call the underlying close! this didn't seem right, so i added it, and my code
>>now works simply and as expected.
>>
>> def close(self):
>> self._sock.close() # added 2003-oct-13
>> self._sock = _closedsocket()
>> self.send = self.recv = self.sendto = self.recvfrom = self._sock._dummy
>> close.__doc__ = _realsocket.close.__doc__
>>
>>Probably only on win32, the comments in the socket module seem to indicate
>>different codings on different platforms.
>
>
> None of this should be necessary!
>
> What problems were you having that led you to try the above abomination in
> your effort to resolve them?
>
> -Peter
The problem is i couldn't find anyway, in 'normal' code, to close a server
socket, ie unblock an accept.
tried to use non-blocking mode, but not allowed on a server socket, which
makes sense, but isn't documented.
tried to use time-outs, which was close, but seems to close the accepted
connection sockets on a server socket time-out.
tried to fire a dummy connection to unblock the accept, which works, but if
your ip changes, i.e. a dialup, you can't do that.
i only hacked the module because of frustration, but it took about a minute to
spot, and now every thing works the original way i tried, and i've been doing
some thrashing and had no problems.
More information about the Python-list
mailing list