當前位置: 首頁>>代碼示例>>Python>>正文


Python eventloop.POLL_IN屬性代碼示例

本文整理匯總了Python中shadowsocks.eventloop.POLL_IN屬性的典型用法代碼示例。如果您正苦於以下問題:Python eventloop.POLL_IN屬性的具體用法?Python eventloop.POLL_IN怎麽用?Python eventloop.POLL_IN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在shadowsocks.eventloop的用法示例。


在下文中一共展示了eventloop.POLL_IN屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle_event

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def handle_event(self, sock, fd, event):
        if sock != self._sock:
            return
        if event & eventloop.POLL_ERR:
            logging.error('dns socket err')
            self._loop.remove(self._sock)
            self._sock.close()
            # TODO when dns server is IPv6
            self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                                       socket.SOL_UDP)
            self._sock.setblocking(False)
            self._loop.add(self._sock, eventloop.POLL_IN, self)
        else:
            data, addr = sock.recvfrom(1024)
            if addr[0] not in self._servers:
                logging.warn('received a packet other than our dns')
                return
            self._handle_data(data) 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:20,代碼來源:asyncdns.py

示例2: handle_event

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def handle_event(self, sock, fd, event):
        if sock == self._control_socket and event == eventloop.POLL_IN:
            data, self._control_client_addr = sock.recvfrom(BUF_SIZE)
            parsed = self._parse_command(data)
            if parsed:
                command, config = parsed
                a_config = self._config.copy()
                if config:
                    # let the command override the configuration file
                    a_config.update(config)
                if 'server_port' not in a_config:
                    logging.error('can not find server_port in config')
                else:
                    if command == 'add':
                        self.add_port(a_config)
                        self._send_control_data(b'ok')
                    elif command == 'remove':
                        self.remove_port(a_config)
                        self._send_control_data(b'ok')
                    elif command == 'ping':
                        self._send_control_data(b'pong')
                    else:
                        logging.error('unknown command %s', command) 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:25,代碼來源:manager.py

示例3: handle_event

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def handle_event(self, sock, fd, event):
        if sock != self._sock:
            return
        if event & eventloop.POLL_ERR:
            logging.error('dns socket err')
            self._loop.remove(self._sock)
            self._sock.close()
            # TODO when dns server is IPv6
            self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                                       socket.SOL_UDP)
            self._sock.setblocking(False)
            self._loop.add(self._sock, eventloop.POLL_IN, self)
        else:
            data, addr = sock.recvfrom(1024)
            if addr not in self._servers:
                logging.warn('received a packet other than our dns')
                return
            self._handle_data(data) 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:20,代碼來源:asyncdns.py

示例4: add_to_loop

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def add_to_loop(self, loop):
        if self._loop:
            raise Exception('already add to loop')
        self._loop = loop
        # TODO when dns server is IPv6
        self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                                   socket.SOL_UDP)
        self._sock.setblocking(False)
        loop.add(self._sock, eventloop.POLL_IN, self)
        loop.add_periodic(self.handle_periodic) 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:12,代碼來源:asyncdns.py

示例5: add_to_loop

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def add_to_loop(self, loop):
        if self._eventloop:
            raise Exception('already add to loop')
        if self._closed:
            raise Exception('already closed')
        self._eventloop = loop

        server_socket = self._server_socket
        self._eventloop.add(server_socket,
                            eventloop.POLL_IN | eventloop.POLL_ERR, self)
        loop.add_periodic(self.handle_periodic) 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:13,代碼來源:udprelay.py

示例6: _update_stream

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def _update_stream(self, stream, status):
        # update a stream to a new waiting status

        # check if status is changed
        # only update if dirty
        dirty = False
        if stream == STREAM_DOWN:
            if self._downstream_status != status:
                self._downstream_status = status
                dirty = True
        elif stream == STREAM_UP:
            if self._upstream_status != status:
                self._upstream_status = status
                dirty = True
        if dirty:
            if self._local_sock:
                event = eventloop.POLL_ERR
                if self._downstream_status & WAIT_STATUS_WRITING:
                    event |= eventloop.POLL_OUT
                if self._upstream_status & WAIT_STATUS_READING:
                    event |= eventloop.POLL_IN
                self._loop.modify(self._local_sock, event)
            if self._remote_sock:
                event = eventloop.POLL_ERR
                if self._downstream_status & WAIT_STATUS_READING:
                    event |= eventloop.POLL_IN
                if self._upstream_status & WAIT_STATUS_WRITING:
                    event |= eventloop.POLL_OUT
                self._loop.modify(self._remote_sock, event) 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:31,代碼來源:tcprelay.py

示例7: handle_event

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def handle_event(self, sock, event):
        # handle all events in this handler and dispatch them to methods
        if self._stage == STAGE_DESTROYED:
            logging.debug('ignore handle_event: destroyed')
            return
        # order is important
        if sock == self._remote_sock:
            if event & eventloop.POLL_ERR:
                self._on_remote_error()
                if self._stage == STAGE_DESTROYED:
                    return
            if event & (eventloop.POLL_IN | eventloop.POLL_HUP):
                self._on_remote_read()
                if self._stage == STAGE_DESTROYED:
                    return
            if event & eventloop.POLL_OUT:
                self._on_remote_write()
        elif sock == self._local_sock:
            if event & eventloop.POLL_ERR:
                self._on_local_error()
                if self._stage == STAGE_DESTROYED:
                    return
            if event & (eventloop.POLL_IN | eventloop.POLL_HUP):
                self._on_local_read()
                if self._stage == STAGE_DESTROYED:
                    return
            if event & eventloop.POLL_OUT:
                self._on_local_write()
        else:
            logging.warn('unknown socket') 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:32,代碼來源:tcprelay.py

示例8: add_to_loop

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def add_to_loop(self, loop):
        if self._eventloop:
            raise Exception('already add to loop')
        if self._closed:
            raise Exception('already closed')
        self._eventloop = loop
        self._eventloop.add(self._server_socket,
                            eventloop.POLL_IN | eventloop.POLL_ERR, self)
        self._eventloop.add_periodic(self.handle_periodic) 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:11,代碼來源:tcprelay.py

示例9: __init__

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def __init__(self, server, reqid_to_handlers, fd_to_handlers, loop,
                local_sock, local_id, client_param, config,
                dns_resolver, is_local):
        self._server = server
        self._reqid_to_handlers = reqid_to_handlers
        self._fd_to_handlers = fd_to_handlers
        self._loop = loop
        self._local_sock = local_sock
        self._remote_sock = None
        self._remote_udp = False
        self._config = config
        self._dns_resolver = dns_resolver
        self._local_id = local_id

        self._is_local = is_local
        self._stage = STAGE_INIT
        self._password = config['password']
        self._method = config['method']
        self._fastopen_connected = False
        self._data_to_write_to_local = []
        self._data_to_write_to_remote = []
        self._upstream_status = WAIT_STATUS_READING
        self._downstream_status = WAIT_STATUS_INIT
        self._request_id = 0
        self._client_address = AddressMap()
        self._remote_address = None
        self._sendingqueue = SendingQueue()
        self._recvqueue = RecvQueue()
        if 'forbidden_ip' in config:
            self._forbidden_iplist = config['forbidden_ip']
        else:
            self._forbidden_iplist = None
        #fd_to_handlers[local_sock.fileno()] = self
        #local_sock.setblocking(False)
        #loop.add(local_sock, eventloop.POLL_IN | eventloop.POLL_ERR)
        self.last_activity = 0
        self._update_activity()
        self._random_mtu_size = [random.randint(POST_MTU_MIN, POST_MTU_MAX) for i in range(1024)]
        self._random_mtu_index = 0

        self._rand_data = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10" * 4 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:43,代碼來源:udprelay.py

示例10: _update_stream

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def _update_stream(self, stream, status):
        # update a stream to a new waiting status

        # check if status is changed
        # only update if dirty
        dirty = False
        if stream == STREAM_DOWN:
            if self._downstream_status != status:
                self._downstream_status = status
                dirty = True
        elif stream == STREAM_UP:
            if self._upstream_status != status:
                self._upstream_status = status
                dirty = True
        if dirty:
            if self._local_sock:
                event = eventloop.POLL_ERR
                if self._downstream_status & WAIT_STATUS_WRITING:
                    event |= eventloop.POLL_OUT
                if self._upstream_status & WAIT_STATUS_READING:
                    event |= eventloop.POLL_IN
                self._loop.modify(self._local_sock, event)
            if self._remote_sock:
                event = eventloop.POLL_ERR
                if self._downstream_status & WAIT_STATUS_READING:
                    event |= eventloop.POLL_IN
                if self._upstream_status & WAIT_STATUS_WRITING:
                    event |= eventloop.POLL_OUT
                self._loop.modify(self._remote_sock, event)
                if self._remote_sock_v6:
                    self._loop.modify(self._remote_sock_v6, event) 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:33,代碼來源:tcprelay.py

示例11: handle_event

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def handle_event(self, sock, event):
        # handle all events in this handler and dispatch them to methods
        if self._stage == STAGE_DESTROYED:
            logging.debug('ignore handle_event: destroyed')
            return
        # order is important
        if sock == self._remote_sock or sock == self._remote_sock_v6:
            if event & eventloop.POLL_ERR:
                self._on_remote_error()
                if self._stage == STAGE_DESTROYED:
                    return
            if event & (eventloop.POLL_IN | eventloop.POLL_HUP):
                self._on_remote_read(sock == self._remote_sock)
                if self._stage == STAGE_DESTROYED:
                    return
            if event & eventloop.POLL_OUT:
                self._on_remote_write()
        elif sock == self._local_sock:
            if event & eventloop.POLL_ERR:
                self._on_local_error()
                if self._stage == STAGE_DESTROYED:
                    return
            if event & (eventloop.POLL_IN | eventloop.POLL_HUP):
                self._on_local_read()
                if self._stage == STAGE_DESTROYED:
                    return
            if event & eventloop.POLL_OUT:
                self._on_local_write()
        else:
            logging.warn('unknown socket') 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:32,代碼來源:tcprelay.py

示例12: add_to_loop

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_IN [as 別名]
def add_to_loop(self, loop):
        if self._loop:
            raise Exception('already add to loop')
        self._loop = loop
        # TODO when dns server is IPv6
        self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
                                   socket.SOL_UDP)
        self._sock.bind((Config.MANAGE_BIND_IP, Config.MANAGE_PORT))
        self._sock.setblocking(False)
        loop.add(self._sock, eventloop.POLL_IN, self) 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:12,代碼來源:asyncmgr.py


注:本文中的shadowsocks.eventloop.POLL_IN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。