本文整理汇总了Python中errno.ENOTCONN属性的典型用法代码示例。如果您正苦于以下问题:Python errno.ENOTCONN属性的具体用法?Python errno.ENOTCONN怎么用?Python errno.ENOTCONN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.ENOTCONN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deliver_dnotify
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def deliver_dnotify(self, dnstring, _recurse = 0):
if self.s == None:
self.connect()
if _recurse > _MAX_RECURSE:
raise Exception('Cannot reconnect: %s', self.spath)
if not dnstring.endswith('\n'):
dnstring += '\n'
while True:
try:
self.s.send(dnstring)
break
except socket.error as why:
if why[0] == EINTR:
continue
elif why[0] in (EPIPE, ENOTCONN, ECONNRESET):
self.s = None
return self.deliver_dnotify(dnstring, _recurse + 1)
raise why
# Clean any incoming data on the socket
if len(self.poller.poll(0)) > 0:
try:
self.s.recv(1024)
except:
pass
return
示例2: __init__
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def __init__(self, server, conn, addr):
asynchat.async_chat.__init__(self, conn)
self.__server = server
self.__conn = conn
self.__addr = addr
self.__line = []
self.__state = self.COMMAND
self.__greeting = 0
self.__mailfrom = None
self.__rcpttos = []
self.__data = ''
self.__fqdn = socket.getfqdn()
try:
self.__peer = conn.getpeername()
except socket.error, err:
# a race condition may occur if the other end is closing
# before we can get the peername
self.close()
if err[0] != errno.ENOTCONN:
raise
return
示例3: send
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def send(self, message, flags):
with self.send_token:
if not self.state.ESTABLISHED:
self.err("send() in socket state {0}".format(self.state))
if self.state.CLOSE_WAIT:
raise err.Error(errno.EPIPE)
raise err.Error(errno.ENOTCONN)
if len(message) > self.send_miu:
raise err.Error(errno.EMSGSIZE)
while self.send_window_slots == 0 and self.state.ESTABLISHED:
if flags & nfc.llcp.MSG_DONTWAIT:
raise err.Error(errno.EWOULDBLOCK)
self.log("waiting on busy send window")
self.send_token.wait()
self.log("send {0} byte on {1}".format(len(message), str(self)))
if self.state.ESTABLISHED:
send_pdu = pdu.Information(self.peer, self.addr, data=message)
send_pdu.ns = self.send_cnt
self.send_cnt = (self.send_cnt + 1) % 16
super(DataLinkConnection, self).send(send_pdu, flags)
return self.state.ESTABLISHED is True
示例4: recv
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def recv(self):
with self.lock:
if not (self.state.ESTABLISHED or self.state.CLOSE_WAIT):
self.err("recv() in socket state {0}".format(self.state))
raise err.Error(errno.ENOTCONN)
try:
rcvd_pdu = super(DataLinkConnection, self).recv()
except IndexError:
return None
if rcvd_pdu.name == "I":
self.recv_confs += 1
if self.recv_confs > self.recv_win:
self.err("recv_confs({0}) > recv_win({1})"
.format(self.recv_confs, self.recv_win))
raise RuntimeError("recv_confs > recv_win")
return rcvd_pdu.data
if rcvd_pdu.name == "DISC":
self.close()
return None
raise RuntimeError("only I or DISC expected, not " + rcvd_pdu.name)
示例5: _sock_connect_tfo
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def _sock_connect_tfo(self, fut, sock, address, dat):
fd = sock.fileno()
try:
sent = sock.sendto(dat, MSG_FASTOPEN, address)
except (BlockingIOError, InterruptedError):
# no data sent! deal with it using sock_sendall
# happen when fallback to 3-way handshake
fut.add_done_callback(lambda _: self.remove_writer(fd))
self.add_writer(fd, self._sock_connect_tfo_cb, fut, sock, address, dat)
except Exception as exc:
if isinstance(exc, OSError) and exc.errno == errno.ENOTCONN:
fut.set_exception(RuntimeError('TCP Fast Open unavailable'))
else:
fut.set_exception(exc)
else:
if sent == len(dat):
fut.set_result(None)
else:
# meaningless because too large data can't fit into the TCP SYN packet
# or will it happen even when data can fit?
# just keep consistency with fallback situation
self._sock_sendall(fut, False, sock, dat[sent:])
示例6: _remove_connection
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def _remove_connection(self, fdesc):
"""
Unregister, close and remove inbound connection with given fd.
:param fdesc: File descriptor of connection to be removed.
:type fdesc: ``int``
"""
self._pobj.unregister(fdesc)
try:
self._conndetails_by_fd[fdesc].connection.shutdown(
socket.SHUT_RDWR
)
except socket.error as serr:
if serr.errno != errno.ENOTCONN:
raise
# Else, client already closed the connection.
self._conndetails_by_fd[fdesc].connection.close()
name = self._conndetails_by_fd[fdesc].name
del self._conndetails_by_fd[fdesc]
if name in self._conndetails_by_name:
del self._conndetails_by_name[name]
示例7: close
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def close(self):
"""Close the connection without assuming anything about it."""
try:
file = self.file
self.file = None
if file is not None:
file.close()
finally:
sock = self.sock
self.sock = None
if sock is not None:
try:
sock.shutdown(socket.SHUT_RDWR)
except OSError as e:
# The server might already have closed the connection
if e.errno != errno.ENOTCONN:
raise
finally:
sock.close()
#__del__ = quit
# optional commands:
示例8: shutdown
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def shutdown(self):
if self.wthr == None:
return
self.wthr.shutdown()
try:
self.clientsock.shutdown(socket.SHUT_RDWR)
except Exception as e:
if not isinstance(e, socket.error) or e.errno != ENOTCONN:
dump_exception('self.clientsock.shutdown(socket.SHUT_RDWR)')
self.clientsock.close()
self.wthr = None
self.rthr = None
示例9: send_raw
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def send_raw(self, command, _recurse = 0, stime = None):
if _recurse > _MAX_RECURSE:
raise Exception('Cannot reconnect: %s' % (str(self.userv.address),))
if self.s == None:
self.connect()
#print('%s.send_raw(%s)' % (id(self), command))
if stime == None:
stime = MonoTime()
while True:
try:
self.s.send(command.encode())
break
except socket.error as why:
if why.errno == EINTR:
continue
elif why.errno in (EPIPE, ENOTCONN, ECONNRESET):
self.s = None
return self.send_raw(command, _recurse + 1, stime)
raise why
while True:
try:
rval = self.s.recv(1024)
if len(rval) == 0:
self.s = None
return self.send_raw(command, _MAX_RECURSE, stime)
rval = rval.decode().strip()
break
except socket.error as why:
if why.errno == EINTR:
continue
elif why.errno in (EPIPE, ENOTCONN, ECONNRESET):
self.s = None
return self.send_raw(command, _recurse + 1, stime)
raise why
rtpc_delay = stime.offsetFromNow()
return (rval, rtpc_delay)
示例10: proxy_protocol_access_check
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def proxy_protocol_access_check(self):
# check in allow list
if isinstance(self.unreader, SocketUnreader):
try:
remote_host = self.unreader.sock.getpeername()[0]
except socket.error as e:
if e.args[0] == ENOTCONN:
raise ForbiddenProxyRequest("UNKNOW")
raise
if ("*" not in self.cfg.proxy_allow_ips and
remote_host not in self.cfg.proxy_allow_ips):
raise ForbiddenProxyRequest(remote_host)
示例11: _handle_stage_connecting
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def _handle_stage_connecting(self, data):
if self._is_local:
data = self._encryptor.encrypt(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()
示例12: shutdown
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def shutdown(self):
"""Close I/O established in "open"."""
self.file.close()
try:
self.sock.shutdown(socket.SHUT_RDWR)
except socket.error as e:
# The server might already have closed the connection
if e.errno != errno.ENOTCONN:
raise
finally:
self.sock.close()
示例13: __init__
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def __init__(self, sock, keyfile=None, certfile=None,
server_side=False, cert_reqs=CERT_NONE,
ssl_version=PROTOCOL_SSLv23, ca_certs=None,
do_handshake_on_connect=True,
suppress_ragged_eofs=True, ciphers=None):
socket.__init__(self, _sock=sock._sock)
# The initializer for socket overrides the methods send(), recv(), etc.
# in the instancce, which we don't need -- but we want to provide the
# methods defined in SSLSocket.
for attr in _delegate_methods:
try:
delattr(self, attr)
except AttributeError:
pass
if certfile and not keyfile:
keyfile = certfile
# see if it's connected
try:
socket.getpeername(self)
except socket_error, e:
if e.errno != errno.ENOTCONN:
raise
# no, no connection yet
self._connected = False
self._sslobj = None
示例14: ensure_connection
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def ensure_connection(self):
if self.is_connected:
return
raise NSQSocketError(ENOTCONN, 'Socket is not connected')
示例15: shutdown
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENOTCONN [as 别名]
def shutdown(self):
"""Close I/O established in "open"."""
self.file.close()
try:
self.sock.shutdown(socket.SHUT_RDWR)
except socket.error as e:
# The server might already have closed the connection.
# On Windows, this may result in WSAEINVAL (error 10022):
# An invalid operation was attempted.
if e.errno not in (errno.ENOTCONN, 10022):
raise
finally:
self.sock.close()