]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#9354: Provide getsockopt() in asyncore file_wrapper(). Patch by Lukas Langa.
authorGeorg Brandl <georg@python.org>
Wed, 28 Jul 2010 08:19:35 +0000 (08:19 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 28 Jul 2010 08:19:35 +0000 (08:19 +0000)
Lib/asyncore.py
Lib/test/test_asyncore.py
Misc/ACKS
Misc/NEWS

index c2ec259b46f08e61f3116476addc2de4d9aa663a..fba55e0d89515725ef37d750392a987302b63c46 100644 (file)
@@ -607,6 +607,14 @@ if os.name == 'posix':
         def send(self, *args):
             return os.write(self.fd, *args)
 
+        def getsockopt(self, level, optname, buflen=None):
+            if (level == socket.SOL_SOCKET and
+                optname == socket.SO_ERROR and
+                not buflen):
+                return 0
+            raise NotImplementedError("Only asyncore specific behaviour "
+                                      "implemented.")
+
         read = recv
         write = send
 
index 5a1b83ce627903be71630b35e4358b69b5a1b098..ce0a84fa7a5dd3efdc6db5ae9a6310e1aa209679 100644 (file)
@@ -428,6 +428,19 @@ class FileWrapperTest(unittest.TestCase):
         w.close()
         self.assertEqual(open(TESTFN, 'rb').read(), self.d + d1 + d2)
 
+    @unittest.skipUnless(hasattr(asyncore, 'file_dispatcher'),
+                         'asyncore.file_dispatcher required')
+    def test_dispatcher(self):
+        fd = os.open(TESTFN, os.O_RDONLY)
+        data = []
+        class FileDispatcher(asyncore.file_dispatcher):
+            def handle_read(self):
+                data.append(self.recv(29))
+        s = FileDispatcher(fd)
+        os.close(fd)
+        asyncore.loop(timeout=0.01, use_poll=True, count=2)
+        self.assertEqual(b"".join(data), self.d)
+
 
 class BaseTestHandler(asyncore.dispatcher):
 
index 57065ac64d7d1952af99e75140464d13080d31f0..a94318b3cd2a75d455745c28293939d006ca9c47 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -448,8 +448,8 @@ Andrew Kuchling
 Vladimir Kushnir
 Cameron Laird
 Torsten Landschoff
-Tino Lange
 Ćukasz Langa
+Tino Lange
 Andrew Langmead
 Detlef Lannert
 Soren Larsen
index 81ec74e044ffa74dd9ea39fa86d69db3393b25ad..27b326089fb9c88e8888726bcab888a4b302620e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -475,6 +475,8 @@ C-API
 Library
 -------
 
+- Issue #9354: Provide getsockopt() in asyncore's file_wrapper.
+
 - Issue #8966: ctypes: Remove implicit bytes-unicode conversion.
 
 - Issue #9378: python -m pickle <pickle file> will now load and