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


Python eventloop.POLL_ERR屬性代碼示例

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


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

示例1: handle_event

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_ERR [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_ERR [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

示例3: add_to_loop

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_ERR [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

示例4: handle_event

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_ERR [as 別名]
def handle_event(self, sock, fd, event):
        if sock == self._server_socket:
            if event & eventloop.POLL_ERR:
                logging.error('UDP server_socket err')
            self._handle_server()
        elif sock and (fd in self._sockets):
            if event & eventloop.POLL_ERR:
                logging.error('UDP client_socket err')
            self._handle_client(sock) 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:11,代碼來源:udprelay.py

示例5: __init__

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

        # TCP Relay works as either sslocal or ssserver
        # if is_local, this is sslocal
        self._is_local = is_local
        self._stage = STAGE_INIT
        self._encryptor = encrypt.Encryptor(config['password'],
                                            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._client_address = local_sock.getpeername()[:2]
        self._remote_address = None
        if 'forbidden_ip' in config:
            self._forbidden_iplist = config['forbidden_ip']
        else:
            self._forbidden_iplist = None
        if is_local:
            self._chosen_server = self._get_a_server()
        fd_to_handlers[local_sock.fileno()] = self
        local_sock.setblocking(False)
        local_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
        loop.add(local_sock, eventloop.POLL_IN | eventloop.POLL_ERR,
                 self._server)
        self.last_activity = 0
        self._update_activity() 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:38,代碼來源:tcprelay.py

示例6: _update_stream

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_ERR [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_ERR [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_ERR [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_ERR [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_ERR [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:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:33,代碼來源:udprelay.py

示例11: _update_stream

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_ERR [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

示例12: _handle_stage_connecting

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_ERR [as 別名]
def _handle_stage_connecting(self, data):
        if self._is_local:
            data = self._protocol.client_pre_encrypt(data)
            data = self._encryptor.encrypt(data)
            data = self._obfs.client_encode(data)
        if data:
            self._data_to_write_to_remote.append(data)
        if self._is_local and not self._fastopen_connected and \
                self._config['fast_open']:
            # for sslocal and fastopen, we basically wait for data and use
            # sendto to connect
            try:
                # only connect once
                self._fastopen_connected = True
                remote_sock = \
                    self._create_remote_socket(self._chosen_server[0],
                                               self._chosen_server[1])
                self._loop.add(remote_sock, eventloop.POLL_ERR, self._server)
                data = b''.join(self._data_to_write_to_remote)
                l = len(data)
                s = remote_sock.sendto(data, MSG_FASTOPEN, self._chosen_server)
                if s < l:
                    data = data[s:]
                    self._data_to_write_to_remote = [data]
                else:
                    self._data_to_write_to_remote = []
                self._update_stream(STREAM_UP, WAIT_STATUS_READWRITING)
            except (OSError, IOError) as e:
                if eventloop.errno_from_exception(e) == errno.EINPROGRESS:
                    # in this case data is not sent at all
                    self._update_stream(STREAM_UP, WAIT_STATUS_READWRITING)
                elif eventloop.errno_from_exception(e) == errno.ENOTCONN:
                    logging.error('fast open not supported on this OS')
                    self._config['fast_open'] = False
                    self.destroy()
                else:
                    shell.print_exception(e)
                    if self._config['verbose']:
                        traceback.print_exc()
                    self.destroy() 
開發者ID:shadowsocksr-backup,項目名稱:shadowsocksr,代碼行數:42,代碼來源:tcprelay.py

示例13: handle_event

# 需要導入模塊: from shadowsocks import eventloop [as 別名]
# 或者: from shadowsocks.eventloop import POLL_ERR [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


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