当前位置: 首页>>代码示例>>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;未经允许,请勿转载。