kopia lustrzana https://github.com/micropython/micropython-lib
select: Actually implement extended arg to epoll.register().
Allow to pass arbitrary Python objects as "callback data" to epoll, which will be then returned when activity on fd detected.asyncio-segfault
rodzic
b149831264
commit
1cc01656f7
|
@ -23,14 +23,19 @@ EPOLL_CTL_MOD = 3
|
||||||
|
|
||||||
class Epoll:
|
class Epoll:
|
||||||
|
|
||||||
|
# Second value is actually of uint64_t size, so struct
|
||||||
|
# will be smaller on 32bit, but seem to not segfault.
|
||||||
|
epoll_event = "IO"
|
||||||
|
|
||||||
def __init__(self, epfd):
|
def __init__(self, epfd):
|
||||||
self.epfd = epfd
|
self.epfd = epfd
|
||||||
self.evbuf = struct.pack("IQ", 0, 0)
|
self.evbuf = struct.pack(self.epoll_event, 0, 0)
|
||||||
|
|
||||||
def register(self, fd, eventmask=EPOLLIN|EPOLLPRI|EPOLLOUT, retval=None):
|
def register(self, fd, eventmask=EPOLLIN|EPOLLPRI|EPOLLOUT, retval=None):
|
||||||
|
"retval is extension to stdlib, value to use in results from .poll()."
|
||||||
if retval is None:
|
if retval is None:
|
||||||
retval = fd
|
retval = fd
|
||||||
s = struct.pack("IQ", eventmask, retval)
|
s = struct.pack(self.epoll_event, eventmask, retval)
|
||||||
r = epoll_ctl(self.epfd, EPOLL_CTL_ADD, fd, s)
|
r = epoll_ctl(self.epfd, EPOLL_CTL_ADD, fd, s)
|
||||||
os.check_error(r)
|
os.check_error(r)
|
||||||
|
|
||||||
|
@ -40,8 +45,8 @@ class Epoll:
|
||||||
os.check_error(n)
|
os.check_error(n)
|
||||||
res = []
|
res = []
|
||||||
if n > 0:
|
if n > 0:
|
||||||
ev, h = struct.unpack("IQ", s)
|
vals = struct.unpack(self.epoll_event, s)
|
||||||
res.append((h, ev))
|
res.append((vals[1], vals[0]))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ sys.path.pop(0)
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
setup(name='micropython-select',
|
setup(name='micropython-select',
|
||||||
version='0.0.1',
|
version='0.0.2',
|
||||||
description='select module to MicroPython',
|
description='select module to MicroPython',
|
||||||
url='https://github.com/micropython/micropython/issues/405',
|
url='https://github.com/micropython/micropython/issues/405',
|
||||||
author='Paul Sokolovsky',
|
author='Paul Sokolovsky',
|
||||||
|
|
|
@ -3,7 +3,7 @@ import os
|
||||||
|
|
||||||
|
|
||||||
ep = select.epoll()
|
ep = select.epoll()
|
||||||
ep.register(0, select.EPOLLIN)
|
ep.register(0, select.EPOLLIN, (lambda x:x, (0,)))
|
||||||
res = ep.poll(2000)
|
res = ep.poll(2000)
|
||||||
print(res)
|
print(res)
|
||||||
for ev, fd in res:
|
for ev, fd in res:
|
||||||
|
|
Ładowanie…
Reference in New Issue