timeoutsocket & sendall / Python 2.1

John J Lee jjl at pobox.com
Fri Nov 15 17:36:45 EST 2002


It seems that Python 2.1 added a sendall method to socket objects.  I
think something like this needs adding to timeoutsocket.py:

    def send(self, data, flags=0):
        sock = self._sock
        if self._blocking:
            r,w,e = select.select([],[sock],[], self._timeout)
            if not w:
                raise Timeout("Send timed out")
        return sock.send(data, flags)
    # end send

+   def sendall(self, data, flags=0):
+       while data:
+           n = self.send(data, flags)
+           data = data[n:]
+   # end sendall

    def recv(self, bufsize, flags=0):
        sock = self._sock


I've never used sockets directly, so apologies if this is broken /
hopelessly naive.

I'm surprised that nobody has bumped into this before, which is
why I'm posting it here -- I have a feeling I must be missing
something.


John




More information about the Python-list mailing list