diff --git a/Lib/asyncore.py b/Lib/asyncore.py index ee0a049c179..d3301b0052e 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -594,6 +594,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 ebc2adbfa2d..56f1939acde 100644 --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -412,6 +412,17 @@ if hasattr(asyncore, 'file_wrapper'): w.close() self.assertEqual(file(TESTFN).read(), self.d + d1 + d2) + 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("".join(data), self.d) + def test_main(): tests = [HelperFunctionTests, DispatcherTests, DispatcherWithSendTests, diff --git a/Misc/ACKS b/Misc/ACKS index 2f6055e5836..dd86e5c070d 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -407,6 +407,7 @@ Ivan Krstić Andrew Kuchling Vladimir Kushnir Cameron Laird +Łukasz Langa Tino Lange Andrew Langmead Detlef Lannert diff --git a/Misc/NEWS b/Misc/NEWS index 2f25dcb7228..b0e66a39b26 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -35,6 +35,8 @@ Core and Builtins when turned into an exception: in this case the exception simply gets ignored. +- Issue #9354: Provide getsockopt() in asyncore's file_wrapper. + - In the unicode/str.format(), raise a ValueError when indexes to arguments are too large.