[Zodb-checkins] CVS: StandaloneZODB/ZEO - smac.py:1.9.6.7
Jeremy Hylton
jeremy@zope.com
Wed, 2 Jan 2002 17:52:47 -0500
Update of /cvs-repository/StandaloneZODB/ZEO
In directory cvs.zope.org:/tmp/cvs-serv6151
Modified Files:
Tag: ZEO-ZRPC-Dev
smac.py
Log Message:
Backport changes from ZEO 1.0 to make send/recv robust.
=== StandaloneZODB/ZEO/smac.py 1.9.6.6 => 1.9.6.7 ===
from types import StringType
+import socket, errno
+
+# 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
+
class SizedMessageAsyncConnection(asyncore.dispatcher):
__super_init = asyncore.dispatcher.__init__
__super_close = asyncore.dispatcher.close
@@ -123,7 +143,12 @@
def handle_read(self):
# Use a single __inp buffer and integer indexes to make this
# fast.
- d = self.recv(self.READ_SIZE)
+ try:
+ d=self.recv(8096)
+ except socket.error, err:
+ if err[0] in expected_socket_read_errors:
+ return
+ raise
if not d:
return
@@ -182,7 +207,12 @@
output = self.__output
while output:
v = output[0]
- n = self.send(v)
+ try:
+ n=self.send(v)
+ except socket.error, err:
+ if err[0] in expected_socket_write_errors:
+ break # we couldn't write anything
+ raise
if n < len(v):
output[0] = v[n:]
break # we can't write any more