[Zope-Coders] Re: [Zope-Checkins] CVS: Zope/ZServer/medusa - asyncore.py:1.13.36.1

Jeremy Hylton jeremy@zope.com
Mon, 21 Jan 2002 12:04:13 -0500


>>>>> "BL" == Brian Lloyd <brian@zope.com> writes:

  BL> Backported fix for bug #157: asyncore hang on Linux 2.2.

Is it possible to make these changes in the code that calls asyncore
rather than in asyncore?  Sam Rushing has pushed back against making
changes to catch errors like this inside asyncore.  So it's a hard
sell to get these changes into Python.

Regardless of where the changes are made, the code should check
for a wider range of error conditions and the same changes should be
made for send().  I had to fix ZEO to deal with a bunch of similar
errors.  I used the code below (from ZEO/smac.py).

Jeremy

# Use the dictionary to make sure we get the minimum number of errno
# entries.   We expect that EWOULDBLOCK == EAGAIN on most systems --
# or that only one is actually used.

tmp_dict = {errno.EWOULDBLOCK: 0,
            errno.EAGAIN: 0,
            errno.EINTR: 0,
            }
expected_socket_read_errors = tuple(tmp_dict.keys())

tmp_dict = {errno.EAGAIN: 0,
            errno.EWOULDBLOCK: 0,
            errno.ENOBUFS: 0,
            errno.EINTR: 0,
            }
expected_socket_write_errors = tuple(tmp_dict.keys())
del tmp_dict

[...]

        try:
            d=self.recv(8096)
        except socket.error, err:
            if err[0] in expected_socket_read_errors:
                return
            raise

[...]

            try:
                n=self.send(v)
            except socket.error, err:
                if err[0] in expected_socket_write_errors:
                    break # we couldn't write anything
                raise