1
- # (c) 2014-2018 Paul Sokolovsky. MIT license.
1
+ # (c) 2014-2019 Paul Sokolovsky. MIT license.
2
2
import uerrno
3
3
import uselect as select
4
4
import usocket as _socket
@@ -21,38 +21,31 @@ class PollEventLoop(EventLoop):
21
21
def __init__ (self , runq_len = 16 , waitq_len = 16 ):
22
22
EventLoop .__init__ (self , runq_len , waitq_len )
23
23
self .poller = select .poll ()
24
- self .objmap = {}
25
24
26
25
def add_reader (self , sock , cb , * args ):
27
26
if DEBUG and __debug__ :
28
27
log .debug ("add_reader%s" , (sock , cb , args ))
29
28
if args :
30
- self .poller .register (sock , select .POLLIN )
31
- self .objmap [id (sock )] = (cb , args )
29
+ self .poller .register (sock , select .POLLIN , (cb , args ))
32
30
else :
33
- self .poller .register (sock , select .POLLIN )
34
- self .objmap [id (sock )] = cb
31
+ self .poller .register (sock , select .POLLIN , cb )
35
32
36
33
def remove_reader (self , sock ):
37
34
if DEBUG and __debug__ :
38
35
log .debug ("remove_reader(%s)" , sock )
39
- self .objmap .pop (id (sock ), None )
40
36
self .poller .unregister (sock )
41
37
42
38
def add_writer (self , sock , cb , * args ):
43
39
if DEBUG and __debug__ :
44
40
log .debug ("add_writer%s" , (sock , cb , args ))
45
41
if args :
46
- self .poller .register (sock , select .POLLOUT )
47
- self .objmap [id (sock )] = (cb , args )
42
+ self .poller .register (sock , select .POLLOUT , (cb , args ))
48
43
else :
49
- self .poller .register (sock , select .POLLOUT )
50
- self .objmap [id (sock )] = cb
44
+ self .poller .register (sock , select .POLLOUT , cb )
51
45
52
46
def remove_writer (self , sock ):
53
47
if DEBUG and __debug__ :
54
48
log .debug ("remove_writer(%s)" , sock )
55
- self .objmap .pop (id (sock ), None )
56
49
# StreamWriter.awrite() first tries to write to a socket,
57
50
# and if that succeeds, yield IOWrite may never be called
58
51
# for that socket, and it will never be added to poller. So,
@@ -80,8 +73,7 @@ def wait(self, delay):
80
73
# Remove "if res" workaround after
81
74
# https://github.com/micropython/micropython/issues/2716 fixed.
82
75
if res :
83
- for sock , ev in res :
84
- cb = self .objmap [id (sock )]
76
+ for sock , ev , cb in res :
85
77
if ev & (select .POLLHUP | select .POLLERR ):
86
78
# These events are returned even if not requested, and
87
79
# are sticky, i.e. will be returned again and again.
0 commit comments