2018-09-28 14:54:46 -04:00
|
|
|
|
try:
|
|
|
|
|
import usocket as socket, uselect as select, uerrno as errno
|
|
|
|
|
except ImportError:
|
|
|
|
|
try:
|
|
|
|
|
import socket, select, errno
|
2020-03-22 22:26:08 -04:00
|
|
|
|
|
2018-10-24 05:14:56 -04:00
|
|
|
|
select.poll # Raises AttributeError for CPython implementations without poll()
|
|
|
|
|
except (ImportError, AttributeError):
|
2018-09-28 14:54:46 -04:00
|
|
|
|
print("SKIP")
|
|
|
|
|
raise SystemExit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
poller = select.poll()
|
|
|
|
|
|
|
|
|
|
s = socket.socket()
|
|
|
|
|
|
|
|
|
|
poller.register(s)
|
|
|
|
|
# https://docs.python.org/3/library/select.html#select.poll.register
|
|
|
|
|
# "Registering a file descriptor that’s already registered is not an error,
|
|
|
|
|
# and has the same effect as registering the descriptor exactly once."
|
|
|
|
|
poller.register(s)
|
|
|
|
|
|
|
|
|
|
# 2 args are mandatory unlike register()
|
|
|
|
|
try:
|
|
|
|
|
poller.modify(s)
|
|
|
|
|
except TypeError:
|
|
|
|
|
print("modify:TypeError")
|
|
|
|
|
|
|
|
|
|
poller.modify(s, select.POLLIN)
|
|
|
|
|
|
|
|
|
|
poller.unregister(s)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
poller.modify(s, select.POLLIN)
|
|
|
|
|
except OSError as e:
|
2021-04-22 05:32:21 -04:00
|
|
|
|
assert e.errno == errno.ENOENT
|
2019-10-16 02:24:40 -04:00
|
|
|
|
|
|
|
|
|
# poll after closing the socket, should return POLLNVAL
|
|
|
|
|
poller.register(s)
|
|
|
|
|
s.close()
|
|
|
|
|
p = poller.poll(0)
|
|
|
|
|
print(len(p), p[0][-1])
|