strange socket behaviour

Chris Reay mrchameleon at hotmail.com
Wed Jun 2 14:15:06 EDT 2004


fishboy <fishboy at spamspamspam.com> wrote in message news:<82jrb0t5ss1dtf9qki44qphd13t0vpnl02 at 4ax.com>...
> On Wed, 2 Jun 2004 10:37:21 +0800, "Joe Wong" <joewong at mango.cc>
> wrote:
> 
snip
> 
> 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,
myTimeOut)
for eachSock in rd:
  try:
    dataIn = eachSock.recv(MaxBufSz)
  except socket.error:
    # Server closes session.
    self.closeSession(eachSock, "Socket error - recv")
  else:
    if len(dataIn) > 0:
      # Process, process.
    else:
      # Server closes session.
      self.closeSession(eachSock, "Recvd 0 bytes")
# Check the err list etc, etc.



More information about the Python-list mailing list