本文整理匯總了Python中select.EPOLLIN屬性的典型用法代碼示例。如果您正苦於以下問題:Python select.EPOLLIN屬性的具體用法?Python select.EPOLLIN怎麽用?Python select.EPOLLIN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類select
的用法示例。
在下文中一共展示了select.EPOLLIN屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_fromfd
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def test_fromfd(self):
server, client = self._connected_pair()
ep = select.epoll(2)
ep2 = select.epoll.fromfd(ep.fileno())
ep2.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT)
ep2.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT)
events = ep.poll(1, 4)
events2 = ep2.poll(0.9, 4)
self.assertEqual(len(events), 2)
self.assertEqual(len(events2), 2)
ep.close()
try:
ep2.poll(1, 4)
except IOError, e:
self.assertEqual(e.args[0], errno.EBADF, e)
示例2: __register
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def __register(self, listener, intf=None):
'''will register interface with listener. requires subclass property for listener_sock returning valid socket object.
once registration is complete the thread will exit.'''
# this is being defined here the listener will be able to correlate socket back to interface and send in.
_intf = intf if intf else self._intf
self._Log.debug(f'{self._name} started interface registration for {_intf}')
interface.wait_for_interface(interface=_intf)
self._intf_ip = interface.wait_for_ip(interface=_intf)
l_sock = self.listener_sock
listener.__registered_socks[l_sock.fileno()] = L_SOCK(l_sock, _intf) # TODO: make a namedtuple
# TODO: if we dont re register, and im pretty sure i got rid of that, we shouldnt need to track the interface
# anymore yea? the fd and socket object is all we need, unless we need to get the source ip address. OH. does the
# dns proxy need to grab its interface ip for sending to the client? i dont think so, right? it jsut needs to
# spoof the original destination.
listener.__epoll.register(l_sock.fileno(), select.EPOLLIN)
self._Log.notice(f'{self._name} | {_intf} registered.')
示例3: test_fromfd
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def test_fromfd(self):
server, client = self._connected_pair()
ep = select.epoll(2)
ep2 = select.epoll.fromfd(ep.fileno())
ep2.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT)
ep2.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT)
events = ep.poll(1, 4)
events2 = ep2.poll(0.9, 4)
self.assertEqual(len(events), 2)
self.assertEqual(len(events2), 2)
ep.close()
try:
ep2.poll(1, 4)
except OSError as e:
self.assertEqual(e.args[0], errno.EBADF, e)
else:
self.fail("epoll on closed fd didn't raise EBADF")
示例4: test_close
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def test_close(self):
open_file = open(__file__, "rb")
self.addCleanup(open_file.close)
fd = open_file.fileno()
epoll = select.epoll()
# test fileno() method and closed attribute
self.assertIsInstance(epoll.fileno(), int)
self.assertFalse(epoll.closed)
# test close()
epoll.close()
self.assertTrue(epoll.closed)
self.assertRaises(ValueError, epoll.fileno)
# close() can be called more than once
epoll.close()
# operations must fail with ValueError("I/O operation on closed ...")
self.assertRaises(ValueError, epoll.modify, fd, select.EPOLLIN)
self.assertRaises(ValueError, epoll.poll, 1.0)
self.assertRaises(ValueError, epoll.register, fd, select.EPOLLIN)
self.assertRaises(ValueError, epoll.unregister, fd)
示例5: register
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def register(self, fileobj, events, data=None):
key = super(EpollSelector, self).register(fileobj, events, data)
events_mask = 0
if events & EVENT_READ:
events_mask |= select.EPOLLIN
if events & EVENT_WRITE:
events_mask |= select.EPOLLOUT
_syscall_wrapper(self._epoll.register, False, key.fd, events_mask)
return key
示例6: select
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def select(self, timeout=None):
if timeout is not None:
if timeout <= 0:
timeout = 0.0
else:
# select.epoll.poll() has a resolution of 1 millisecond
# but luckily takes seconds so we don't need a wrapper
# like PollSelector. Just for better rounding.
timeout = math.ceil(timeout * 1e3) * 1e-3
timeout = float(timeout)
else:
timeout = -1.0 # epoll.poll() must have a float.
# We always want at least 1 to ensure that select can be called
# with no file descriptors registered. Otherwise will fail.
max_events = max(len(self._fd_to_key), 1)
ready = []
fd_events = _syscall_wrapper(self._epoll.poll, True,
timeout=timeout,
maxevents=max_events)
for fd, event_mask in fd_events:
events = 0
if event_mask & ~select.EPOLLIN:
events |= EVENT_WRITE
if event_mask & ~select.EPOLLOUT:
events |= EVENT_READ
key = self._key_from_fd(fd)
if key:
ready.append((key, events & key.events))
return ready
示例7: register
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def register(self, fileobj, events, data=None):
key = super(EpollSelector, self).register(fileobj, events, data)
epoll_events = 0
if events & EVENT_READ:
epoll_events |= select.EPOLLIN
if events & EVENT_WRITE:
epoll_events |= select.EPOLLOUT
self._epoll.register(key.fd, epoll_events)
return key
示例8: select
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def select(self, timeout=None):
if timeout is None:
timeout = -1
elif timeout <= 0:
timeout = 0
else:
# epoll_wait() has a resolution of 1 millisecond, round away
# from zero to wait *at least* timeout seconds.
timeout = math.ceil(timeout * 1e3) * 1e-3
max_ev = len(self._fd_to_key)
ready = []
try:
fd_event_list = wrap_error(self._epoll.poll, timeout, max_ev)
except InterruptedError:
return ready
for fd, event in fd_event_list:
events = 0
if event & ~select.EPOLLIN:
events |= EVENT_WRITE
if event & ~select.EPOLLOUT:
events |= EVENT_READ
key = self._key_from_fd(fd)
if key:
ready.append((key, events & key.events))
return ready
示例9: test_add
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def test_add(self):
server, client = self._connected_pair()
ep = select.epoll(2)
try:
ep.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT)
ep.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT)
finally:
ep.close()
# adding by object w/ fileno works, too.
ep = select.epoll(2)
try:
ep.register(server, select.EPOLLIN | select.EPOLLOUT)
ep.register(client, select.EPOLLIN | select.EPOLLOUT)
finally:
ep.close()
ep = select.epoll(2)
try:
# TypeError: argument must be an int, or have a fileno() method.
self.assertRaises(TypeError, ep.register, object(),
select.EPOLLIN | select.EPOLLOUT)
self.assertRaises(TypeError, ep.register, None,
select.EPOLLIN | select.EPOLLOUT)
# ValueError: file descriptor cannot be a negative integer (-1)
self.assertRaises(ValueError, ep.register, -1,
select.EPOLLIN | select.EPOLLOUT)
# IOError: [Errno 9] Bad file descriptor
self.assertRaises(IOError, ep.register, 10000,
select.EPOLLIN | select.EPOLLOUT)
# registering twice also raises an exception
ep.register(server, select.EPOLLIN | select.EPOLLOUT)
self.assertRaises(IOError, ep.register, server,
select.EPOLLIN | select.EPOLLOUT)
finally:
ep.close()
示例10: test_errors
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def test_errors(self):
self.assertRaises(ValueError, select.epoll, -2)
self.assertRaises(ValueError, select.epoll().register, -1,
select.EPOLLIN)
示例11: register
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def register(self, key, f):
BasePoller.register(self, key, f)
self.epoll.register(f.fileno(), select.EPOLLIN | select.EPOLLHUP |
select.EPOLLOUT)
self.fd_to_object[f.fileno()] = f
示例12: poll
# 需要導入模塊: import select [as 別名]
# 或者: from select import EPOLLIN [as 別名]
def poll(self, timeout=None):
if timeout is None:
timeout = -1
rv = []
for fd, event in self.epoll.poll(timeout):
obj = self.fd_to_object[fd]
if event & select.EPOLLIN:
rv.append((obj, 'read'))
if event & select.EPOLLOUT:
rv.append((obj, 'write'))
if event & select.EPOLLHUP:
rv.append((obj, 'close'))
return rv