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

Skip to content

Commit e47c381

Browse files
committed
[Bug #1011606] Only check file descriptors for exceptional conditions if the fd is readable or writable
1 parent 3b2cdad commit e47c381

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Lib/asyncore.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,14 @@ def poll(timeout=0.0, map=None):
107107
if map:
108108
r = []; w = []; e = []
109109
for fd, obj in map.items():
110-
e.append(fd)
111-
if obj.readable():
110+
is_r = obj.readable()
111+
is_w = obj.writable()
112+
if is_r:
112113
r.append(fd)
113-
if obj.writable():
114+
if is_w:
114115
w.append(fd)
116+
if is_r or is_w:
117+
e.append(fd)
115118
if [] == r == w == e:
116119
time.sleep(timeout)
117120
else:
@@ -151,12 +154,15 @@ def poll2(timeout=0.0, map=None):
151154
pollster = select.poll()
152155
if map:
153156
for fd, obj in map.items():
154-
flags = select.POLLERR | select.POLLHUP | select.POLLNVAL
157+
flags = 0
155158
if obj.readable():
156159
flags |= select.POLLIN | select.POLLPRI
157160
if obj.writable():
158161
flags |= select.POLLOUT
159162
if flags:
163+
# Only check for exceptions if object was either readable
164+
# or writable.
165+
flags |= select.POLLERR | select.POLLHUP | select.POLLNVAL
160166
pollster.register(fd, flags)
161167
try:
162168
r = pollster.poll(timeout)

0 commit comments

Comments
 (0)