当前位置: 首页>>代码示例>>Python>>正文


Python select.EPOLLIN属性代码示例

本文整理汇总了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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_epoll.py

示例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.') 
开发者ID:DOWRIGHTTV,项目名称:dnxfirewall-cmd,代码行数:21,代码来源:dnx_parent_classes.py

示例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") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_epoll.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_epoll.py

示例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 
开发者ID:snowflakedb,项目名称:snowflake-connector-python,代码行数:11,代码来源:ssl_wrap_util.py

示例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 
开发者ID:snowflakedb,项目名称:snowflake-connector-python,代码行数:34,代码来源:ssl_wrap_util.py

示例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 
开发者ID:jpush,项目名称:jbox,代码行数:11,代码来源:selectors.py

示例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 
开发者ID:jpush,项目名称:jbox,代码行数:28,代码来源:selectors.py

示例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() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:39,代码来源:test_epoll.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_epoll.py

示例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 
开发者ID:getsentry,项目名称:rb,代码行数:7,代码来源:poll.py

示例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 
开发者ID:getsentry,项目名称:rb,代码行数:15,代码来源:poll.py


注:本文中的select.EPOLLIN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。