Rev 6143: Handle the win32 not-a-socket errors. I think this is ~ready. At least for feedback. in http://bazaar.launchpad.net/~jameinel/bzr/drop-idle-connections-824797

John Arbash Meinel john at arbash-meinel.com
Wed Sep 14 12:40:24 UTC 2011


At http://bazaar.launchpad.net/~jameinel/bzr/drop-idle-connections-824797

------------------------------------------------------------
revno: 6143
revision-id: john at arbash-meinel.com-20110914124017-f9wqua8et07udz61
parent: john at arbash-meinel.com-20110914102447-241ekx9268z6ivxj
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: drop-idle-connections-824797
timestamp: Wed 2011-09-14 14:40:17 +0200
message:
  Handle the win32 not-a-socket errors. I think this is ~ready. At least for feedback.
-------------- next part --------------
=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py	2011-09-14 10:24:47 +0000
+++ b/bzrlib/smart/medium.py	2011-09-14 12:40:17 +0000
@@ -24,6 +24,7 @@
 bzrlib/transport/smart/__init__.py.
 """
 
+import errno
 import os
 import sys
 import time
@@ -32,7 +33,6 @@
 import bzrlib
 from bzrlib.lazy_import import lazy_import
 lazy_import(globals(), """
-import errno
 import select
 import socket
 import thread
@@ -178,6 +178,14 @@
         ui.ui_factory.report_transport_activity(self, bytes, direction)
 
 
+_bad_file_descriptor = (errno.EBADF,)
+if sys.platform == 'win32':
+    # Given on Windows if you pass a closed socket to select.select. Probably
+    # also given if you pass a file handle to select.
+    WSAENOTSOCK = 10038
+    _bad_file_descriptor += (WSAENOTSOCK,)
+
+
 class SmartServerStreamMedium(SmartMedium):
     """Handles smart commands coming over a stream.
 
@@ -273,7 +281,7 @@
                 # select.error doesn't have 'errno', it just has args[0]
                 if getattr(e, 'args', None) is not None:
                     err = e.args[0]
-            if err in (errno.EBADF,):
+            if err in _bad_file_descriptor:
                 # If we are told at this point that socket is no longer a valid
                 # socket, just return 'without timeout'
                 return False
@@ -414,9 +422,9 @@
         :return: Did we timeout? (True if we timed out, False if there is data
             to be read)
         """
-        # TODO: I think on Windows, this has to always return 'False' as well,
-        #       because select.select only works on WinSock objects.
-        if getattr(self._in, 'fileno', None) is None:
+        if (getattr(self._in, 'fileno', None) is None
+            or sys.platform == 'win32'):
+            # You can't select() file descriptors on Windows.
             return False
         return self._wait_on_descriptor(self._in, timeout_seconds)
 

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2011-09-13 12:43:49 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2011-09-14 12:40:17 +0000
@@ -20,6 +20,7 @@
 from cStringIO import StringIO
 import os
 import socket
+import sys
 import threading
 
 import bzrlib
@@ -994,7 +995,12 @@
         with os.fdopen(r_server, 'rb') as rf_server:
             server = medium.SmartServerPipeStreamMedium(
                 rf_server, None, None)
-            self.assertTrue(server._wait_for_bytes_with_timeout(0.01))
+            if sys.platform == 'win32':
+                # Windows cannot select() on a pipe, so we just always return
+                # False to indicate that we have to block.
+                self.assertFalse(server._wait_for_bytes_with_timeout(0.01))
+            else:
+                self.assertTrue(server._wait_for_bytes_with_timeout(0.01))
             os.close(w_client)
             data = server.read_bytes(5)
             self.assertEqual('', data)



More information about the bazaar-commits mailing list