strange socket behaviour

Chris Reay mrchameleon at
Wed Jun 2 20:15:06 CEST 2004

fishboy <fishboy at> wrote in message news:<82jrb0t5ss1dtf9qki44qphd13t0vpnl02 at>...
> On Wed, 2 Jun 2004 10:37:21 +0800, "Joe Wong" <joewong at>
> wrote:
> No, your code is ok.  It's just that closing the local end of the
> socket is undefined in select().  Which is why Windows does one thing
> and Linux the other.  
> Closing the remote end causes the socket to show up as readable with
> zero data.

Precisely. I've been through this myself. My solution on the FreeBSD
server side is (pardon the bad pseudocode):

rd, wr, err = select(myClientSocksList, [], myClientSocksList,
for eachSock in rd:
    dataIn = eachSock.recv(MaxBufSz)
  except socket.error:
    # Server closes session.
    self.closeSession(eachSock, "Socket error - recv")
    if len(dataIn) > 0:
      # Process, process.
      # Server closes session.
      self.closeSession(eachSock, "Recvd 0 bytes")
# Check the err list etc, etc.

More information about the Python-list mailing list