From cbb0ae4a428bae3f5c29a1f8974121bb195299ef Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 28 Jul 2010 08:19:35 +0000 Subject: #9354: Provide getsockopt() in asyncore file_wrapper(). Patch by Lukas Langa. --- Lib/asyncore.py | 8 ++++++++ Lib/test/test_asyncore.py | 13 +++++++++++++ Misc/ACKS | 2 +- Misc/NEWS | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Lib/asyncore.py b/Lib/asyncore.py index c2ec259..fba55e0 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -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 diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py index 5a1b83c..ce0a84f 100644 --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -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): diff --git a/Misc/ACKS b/Misc/ACKS index 57065ac..a94318b 100644 --- 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 diff --git a/Misc/NEWS b/Misc/NEWS index 81ec74e..27b3260 100644 --- 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 will now load and -- cgit v0.12