本文整理汇总了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
示例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
示例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
示例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()
示例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,))
示例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)
示例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)
示例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)
示例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
示例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)
示例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)
示例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)
# ------------------------------------------------------------------------
示例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))
示例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))
示例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