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


Python socket.SO_ERROR屬性代碼示例

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


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

示例1: _make_socket

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def _make_socket(iface_name: str, can_fd: bool) -> socket.SocketType:
    s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
    try:
        s.bind((iface_name,))
        s.setsockopt(socket.SOL_SOCKET, _SO_TIMESTAMP, 1)  # timestamping
        if can_fd:
            s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FD_FRAMES, 1)

        s.setblocking(False)

        if 0 != s.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR):
            raise OSError('Could not configure the socket: getsockopt(SOL_SOCKET, SO_ERROR) != 0')
    except BaseException:
        with contextlib.suppress(Exception):
            s.close()
        raise

    return s 
開發者ID:UAVCAN,項目名稱:pyuavcan,代碼行數:20,代碼來源:_socketcan.py

示例2: _handle_connect

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def _handle_connect(self):
        err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        if err != 0:
            self.error = socket.error(err, os.strerror(err))
            # IOLoop implementations may vary: some of them return
            # an error state before the socket becomes writable, so
            # in that case a connection failure would be handled by the
            # error path in _handle_events instead of here.
            if self._connect_future is None:
                gen_log.warning("Connect error on fd %s: %s",
                                self.socket.fileno(), errno.errorcode[err])
            self.close()
            return
        if self._connect_callback is not None:
            callback = self._connect_callback
            self._connect_callback = None
            self._run_callback(callback)
        if self._connect_future is not None:
            future = self._connect_future
            self._connect_future = None
            future.set_result(self)
        self._connecting = False 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:24,代碼來源:iostream.py

示例3: _handle_connect

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def _handle_connect(self):
        err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        if err != 0:
            self.error = socket.error(err, os.strerror(err))
            # IOLoop implementations may vary: some of them return
            # an error state before the socket becomes writable, so
            # in that case a connection failure would be handled by the
            # error path in _handle_events instead of here.
            gen_log.warning("Connect error on fd %d: %s",
                            self.socket.fileno(), errno.errorcode[err])
            self.close()
            return
        if self._connect_callback is not None:
            callback = self._connect_callback
            self._connect_callback = None
            self._run_callback(callback)
        self._connecting = False 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:19,代碼來源:iostream.py

示例4: handle_connect

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def handle_connect(self):
        """Called when connection is established."""
        self.del_channel()
        if self._idler is not None and not self._idler.cancelled:
            self._idler.cancel()
        if not self.cmd_channel.connected:
            return self.close()
        # fix for asyncore on python < 2.6, meaning we aren't
        # actually connected.
        # test_active_conn_error tests this condition
        err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        if err != 0:
            raise socket.error(err)
        #
        msg = 'Active data connection established.'
        self.cmd_channel.respond('200 ' + msg)
        self.cmd_channel.log_cmd(self._cmd, self._normalized_addr, 200, msg)
        #
        if not self.cmd_channel.connected:
            return self.close()
        # delegate such connection to DTP handler
        handler = self.cmd_channel.dtp_handler(self.socket, self.cmd_channel)
        self.cmd_channel.data_channel = handler
        self.cmd_channel._on_dtp_connection() 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:26,代碼來源:handlers.py

示例5: _connect

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def _connect(self, sock, sa):
        while not self._canceled and not ABORT_FLAG_FUNCTION():
            time.sleep(0.01)
            self._check_timeout()  # this should be done at the beginning of each loop
            status = sock.connect_ex(sa)
            if not status or status in (errno.EISCONN, WIN_EISCONN):
                break
            elif status in (errno.EINPROGRESS, WIN_EWOULDBLOCK):
                self.deadline = time.time() + self._timeout.getConnectTimeout()
            # elif status in (errno.EWOULDBLOCK, errno.EALREADY) or (os.name == 'nt' and status == errno.WSAEINVAL):
            #     pass
            yield

        if self._canceled or ABORT_FLAG_FUNCTION():
            raise CanceledException('Request canceled')

        error = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        if error:
            # TODO: determine when this case can actually happen
            raise socket.error((error,)) 
開發者ID:plexinc,項目名稱:plex-for-kodi,代碼行數:22,代碼來源:asyncadapter.py

示例6: _sock_connect_tfo_cb

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def _sock_connect_tfo_cb(self, fut, sock, address, dat):
        if fut.cancelled():
            return

        try:
            err = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
            if err != 0:
                raise OSError(err, 'ConnectTfo failed %s' % (address,))  # Jump to any except clause below.
        except (BlockingIOError, InterruptedError):
            # socket is still registered, the callback will be retried later
            pass
        except Exception as exc:
            fut.set_exception(exc)
        else:
            if dat:
                self._sock_sendall(fut, False, sock, dat)
            else:
                fut.set_result(None) 
開發者ID:krrr,項目名稱:wstan,代碼行數:20,代碼來源:linux.py

示例7: _sock_connect_cb

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def _sock_connect_cb(self, fut, sock, address):
        if fut.cancelled():
            return

        try:
            err = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
            if err != 0:
                # Jump to any except clause below.
                raise OSError(err, 'Connect call failed %s' % (address,))
        except (BlockingIOError, InterruptedError):
            # socket is still registered, the callback will be retried later
            pass
        except Exception as exc:
            fut.set_exception(exc)
        else:
            fut.set_result(None) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:selector_events.py

示例8: _sock_connect_cb

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def _sock_connect_cb(self, fut, sock, address):
        if fut.cancelled():
            return

        try:
            err = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
            if err != 0:
                # Jump to any except clause below.
                raise OSError(err, f'Connect call failed {address}')
        except (BlockingIOError, InterruptedError):
            # socket is still registered, the callback will be retried later
            pass
        except Exception as exc:
            fut.set_exception(exc)
        else:
            fut.set_result(None) 
開發者ID:CedricGuillemet,項目名稱:Imogen,代碼行數:18,代碼來源:selector_events.py

示例9: _handle_connect

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def _handle_connect(self):
        err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        if err != 0:
            self.error = socket.error(err, os.strerror(err))
            # IOLoop implementations may vary: some of them return
            # an error state before the socket becomes writable, so
            # in that case a connection failure would be handled by the
            # error path in _handle_events instead of here.
            #logging.warning("Connect error on fd %d: %s",
            #                self.socket.fileno(), errno.errorcode[err])
            ht.logger.warning("Connect error on fd %d: %s",
                            self.socket.fileno(), errno.errorcode[err])
            self.close()
            return
        if self._connect_callback is not None:
            callback = self._connect_callback
            self._connect_callback = None
            self._run_callback(callback)
        self._connecting = False 
開發者ID:omererdem,項目名稱:honeything,代碼行數:21,代碼來源:iostream.py

示例10: handle_connect_event

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def handle_connect_event(self):
        if _debug: TCPClient._debug("handle_connect_event")

        # there might be an error
        err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        if _debug: TCPClient._debug("    - err: %r", err)

        # check for connection refused
        if (err == 0):
            if _debug: TCPClient._debug("    - no error")
            self.connected = True
        elif (err == errno.ECONNREFUSED):
            if _debug: TCPClient._debug("    - connection to %r refused", self.peer)
            self.handle_error(socket.error(errno.ECONNREFUSED, "connection refused"))
            return

        # pass along
        asyncore.dispatcher.handle_connect_event(self) 
開發者ID:JoelBender,項目名稱:bacpypes,代碼行數:20,代碼來源:tcp.py

示例11: handle_connect_event

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def handle_connect_event(self):
        if _debug: TCPClient._debug("handle_connect_event")

        # there might be an error
        err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        if _debug: TCPClient._debug("    - err: %r", err)

        # check for connection refused
        if (err == 0):
            if _debug: TCPClient._debug("    - no error")
        elif (err == 111):
            if _debug: TCPClient._debug("    - connection to %r refused", self.peer)
            self.handle_error(socket.error(111, "connection refused"))
            return

        # pass along
        asyncore.dispatcher.handle_connect_event(self) 
開發者ID:JoelBender,項目名稱:bacpypes,代碼行數:19,代碼來源:tcp.py

示例12: OnReadyForWriting

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def OnReadyForWriting(self) :
        if not self._socketOpened :
            if hasattr(self._socket, "getsockopt") :
                if self._socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) :
                    self._close(XClosedReason.Error, triggerOnClosed=False)
                    if self._onFailsToConnect :
                        try :
                            self._onFailsToConnect(self)
                        except Exception as ex :
                            raise XAsyncTCPClientException('Error when handling the "OnFailsToConnect" event : %s' % ex)
                    return
                self._cliAddr = self._socket.getsockname()
                self._removeExpireTimeout()
            self._socketOpened = True
            if self._onConnected :
                try :
                    self._onConnected(self)
                except Exception as ex :
                    raise XAsyncTCPClientException('Error when handling the "OnConnected" event : %s' % ex)
        if self._wrBufView :
            try :
                n = self._socket.send(self._wrBufView)
            except :
                return
            self._wrBufView = self._wrBufView[n:]
            if not self._wrBufView :
                self._asyncSocketsPool.NotifyNextReadyForWriting(self, False)
                if self._onDataSent :
                    try :
                        self._onDataSent(self, self._onDataSentArg)
                    except Exception as ex :
                        raise XAsyncTCPClientException('Error when handling the "OnDataSent" event : %s' % ex)

    # ------------------------------------------------------------------------ 
開發者ID:jczic,項目名稱:MicroWebSrv2,代碼行數:36,代碼來源:XAsyncSockets.py

示例13: get_fd_error

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def get_fd_error(self):
        errno = self.socket.getsockopt(socket.SOL_SOCKET,
                                       socket.SO_ERROR)
        return socket.error(errno, os.strerror(errno)) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:6,代碼來源:iostream.py

示例14: get_sock_error

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def get_sock_error(sock):
    error_number = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
    return socket.error(error_number, os.strerror(error_number)) 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:5,代碼來源:eventloop.py

示例15: handle_connect_event

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import SO_ERROR [as 別名]
def handle_connect_event(self):
        err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        if err != 0:
            raise socket.error(err, _strerror(err))
        self.handle_connect()
        self.connected = True 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:8,代碼來源:asyncore.py


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