Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cbb0ae4

Browse files
committed
#9354: Provide getsockopt() in asyncore file_wrapper(). Patch by Lukas Langa.
1 parent 8182b71 commit cbb0ae4

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lib/asyncore.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,14 @@ def recv(self, *args):
607607
def send(self, *args):
608608
return os.write(self.fd, *args)
609609

610+
def getsockopt(self, level, optname, buflen=None):
611+
if (level == socket.SOL_SOCKET and
612+
optname == socket.SO_ERROR and
613+
not buflen):
614+
return 0
615+
raise NotImplementedError("Only asyncore specific behaviour "
616+
"implemented.")
617+
610618
read = recv
611619
write = send
612620

Lib/test/test_asyncore.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,19 @@ def test_send(self):
428428
w.close()
429429
self.assertEqual(open(TESTFN, 'rb').read(), self.d + d1 + d2)
430430

431+
@unittest.skipUnless(hasattr(asyncore, 'file_dispatcher'),
432+
'asyncore.file_dispatcher required')
433+
def test_dispatcher(self):
434+
fd = os.open(TESTFN, os.O_RDONLY)
435+
data = []
436+
class FileDispatcher(asyncore.file_dispatcher):
437+
def handle_read(self):
438+
data.append(self.recv(29))
439+
s = FileDispatcher(fd)
440+
os.close(fd)
441+
asyncore.loop(timeout=0.01, use_poll=True, count=2)
442+
self.assertEqual(b"".join(data), self.d)
443+
431444

432445
class BaseTestHandler(asyncore.dispatcher):
433446

Misc/ACKS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ Andrew Kuchling
448448
Vladimir Kushnir
449449
Cameron Laird
450450
Torsten Landschoff
451-
Tino Lange
452451
Łukasz Langa
452+
Tino Lange
453453
Andrew Langmead
454454
Detlef Lannert
455455
Soren Larsen

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ C-API
475475
Library
476476
-------
477477

478+
- Issue #9354: Provide getsockopt() in asyncore's file_wrapper.
479+
478480
- Issue #8966: ctypes: Remove implicit bytes-unicode conversion.
479481

480482
- Issue #9378: python -m pickle <pickle file> will now load and

0 commit comments

Comments
 (0)