本文整理汇总了Python中select.EPOLLET属性的典型用法代码示例。如果您正苦于以下问题:Python select.EPOLLET属性的具体用法?Python select.EPOLLET怎么用?Python select.EPOLLET使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类select
的用法示例。
在下文中一共展示了select.EPOLLET属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _poll_queue_event
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def _poll_queue_event(self, events):
"""
EPoll event callback
"""
for fd, event in events:
if not (event & (select.EPOLLPRI | select.EPOLLET)):
continue
try:
values = self._allocated_pins.itervalues()
except AttributeError:
values = self._allocated_pins.values()
for pin in values:
if pin.fileno() == fd:
pin.changed(pin.read())
示例2: bind
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def bind(self):
"""
bind the ip:port
"""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._set_sock_params(sock)
sock.bind((self._bind_ip, self._bind_port))
self._set_sock_nonblocking(sock)
log.info(
'bind port info:(ip:%s, port:%s)' % (
self._bind_ip, self._bind_port
)
)
self._epoll.register(
sock.fileno(),
select.EPOLLIN | select.EPOLLET | select.EPOLLOUT | select.EPOLLERR
)
self._bind_sock = sock
示例3: _handle_new_conn
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def _handle_new_conn(self, newsock, peer):
self._set_sock_params(newsock)
self._set_sock_nonblocking(newsock)
context = sockcontext.CConnContext()
context.set_sock(newsock)
context.set_conn_man(self)
context.set_peerinfo(peer)
self._epoll.register(
newsock.fileno(), select.EPOLLIN | select.EPOLLET | select.EPOLLERR
)
self._rwlock.acquire_writelock()
self._fileno2context[newsock.fileno()] = context
self._peer2context[peer] = context
self._context2fileno_peer[context] = (newsock.fileno(), peer)
self._rwlock.release_writelock()
log.info('a new connection: {0}'.format(peer))
示例4: _run
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def _run(self):
while self._running:
events = self._poll.poll(EPOLL_TIMEOUT)
for fd, event in events:
if not (event & (select.EPOLLPRI | select.EPOLLET)):
continue
self.changed(self.read())
示例5: __init__
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def __init__(self, options = select.EPOLLET, maxwait = 60):
'''
Constructor
'''
self.epoll = select.epoll()
self.defaultoption = options
self.mask = select.EPOLLIN|select.EPOLLPRI|select.EPOLLOUT|\
select.EPOLLRDNORM|select.EPOLLRDBAND|select.EPOLLWRNORM|\
select.EPOLLWRBAND|select.EPOLLONESHOT|select.EPOLLET
self.socketCounter = 0
self.maxwait = maxwait
self.daemons = set()
self.shouldraise = False
示例6: _poll_queue_register_pin
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def _poll_queue_register_pin(self, pin):
''' Pin responds to fileno(), so it's pollable. '''
self._poll_queue.register(pin, (select.EPOLLPRI | select.EPOLLET))
示例7: register
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def register(self, fd, *masks):
masks = [self.from_[x] for x in masks] + [
select.EPOLLET, select.EPOLLERR, select.EPOLLHUP]
self.q.register(fd, reduce(operator.or_, masks, 0))
示例8: __init__
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def __init__(self, server_address):
"""初始化服务器TCP套接字"""
self.tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.tcp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.tcp_socket.bind(server_address)
self.tcp_socket.listen(128)
self.tcp_socket.setblocking(False) # 将套接字设置为非阻塞模式
self.epoll = select.epoll() # 创建一个epoll对象
self.epoll.register(self.tcp_socket.fileno(), select.EPOLLIN | select.EPOLLET) # 将服务套接字注册
self.connections = {}
self.addresses = {}
示例9: serve_forever
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def serve_forever(self):
"""永久运行监听接收连接"""
while True:
epoll_list = self.epoll.poll()
for fd, events in epoll_list:
if fd == self.tcp_socket.fileno():
new_client_socket, new_client_address = self.tcp_socket.accept()
print(new_client_address, '向服务器发起了请求')
self.connections[new_client_socket.fileno()] = new_client_socket # 存入客户连接事件文件描述符
self.addresses[new_client_socket.fileno()] = new_client_address
# 向epoll中则侧新socket的可读事件
self.epoll.register(new_client_socket.fileno(), select.EPOLLIN | select.EPOLLET)
elif events == select.EPOLLIN:
self.handlerequest(fd)
示例10: serve_forever
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def serve_forever(self):
"""永久运行监听接收连接"""
while True:
epoll_list = self.epoll.poll()
for fd, events in epoll_list:
if fd == self.tcp_socket.fileno():
new_client_socket, new_client_address = self.tcp_socket.accept()
print(new_client_address, '向服务器发起了请求')
self.connections[new_client_socket.fileno()] = new_client_socket # 存入客户连接事件文件描述符
self.addresses[new_client_socket.fileno()] = new_client_address
# 向epoll中则侧新socket的可读事件
self.epoll.register(new_client_socket.fileno(), select.EPOLLIN | select.EPOLLET)
elif events == select.EPOLLIN:
td = threading.Thread(target=self.handlerequest, args=(fd,))
td.start()
示例11: _epoll_write_params
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def _epoll_write_params(cls):
return (select.EPOLLET | select.EPOLLOUT | select.EPOLLERR)
示例12: _epoll_read_params
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def _epoll_read_params(cls):
return (select.EPOLLET | select.EPOLLIN | select.EPOLLERR)
示例13: _finish_read_callback
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def _finish_read_callback(self, succ, result):
context = result
if context.is_detroying():
# destroy the context and socket
context.release_readlock()
try:
self.cleanup_error_context(context)
except KeyError:
pass
else:
self._epoll.modify(
context.get_sock().fileno(), select.EPOLLIN | select.EPOLLET
)
context.release_readlock()
示例14: run
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def run(self):
poller = select.epoll()
poller.register(self.fd, self.event_mask | select.EPOLLET)
while self.running:
try:
events = poller.poll(timeout=1)
if events and self.callback is not None:
self.callback()
except OSError as exc:
# poller.poll() will raise an IOError because of the
# interrupted system call when suspending the machine.
logger.debug(f"Ignored IO error: {exc}")
示例15: test_control_and_wait
# 需要导入模块: import select [as 别名]
# 或者: from select import EPOLLET [as 别名]
def test_control_and_wait(self):
client, server = self._connected_pair()
ep = select.epoll(16)
ep.register(server.fileno(),
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
ep.register(client.fileno(),
select.EPOLLIN | select.EPOLLOUT | select.EPOLLET)
now = time.time()
events = ep.poll(1, 4)
then = time.time()
self.assertFalse(then - now > 0.1, then - now)
events.sort()
expected = [(client.fileno(), select.EPOLLOUT),
(server.fileno(), select.EPOLLOUT)]
expected.sort()
self.assertEqual(events, expected)
events = ep.poll(timeout=2.1, maxevents=4)
self.assertFalse(events)
client.send("Hello!")
server.send("world!!!")
now = time.time()
events = ep.poll(1, 4)
then = time.time()
self.assertFalse(then - now > 0.01)
events.sort()
expected = [(client.fileno(), select.EPOLLIN | select.EPOLLOUT),
(server.fileno(), select.EPOLLIN | select.EPOLLOUT)]
expected.sort()
self.assertEqual(events, expected)
ep.unregister(client.fileno())
ep.modify(server.fileno(), select.EPOLLOUT)
now = time.time()
events = ep.poll(1, 4)
then = time.time()
self.assertFalse(then - now > 0.01)
expected = [(server.fileno(), select.EPOLLOUT)]
self.assertEqual(events, expected)