本文整理汇总了Python中errno.EINPROGRESS属性的典型用法代码示例。如果您正苦于以下问题:Python errno.EINPROGRESS属性的具体用法?Python errno.EINPROGRESS怎么用?Python errno.EINPROGRESS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.EINPROGRESS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def __init__ (self):
self.sock = None # socket object
self.send_buf = [] # send buffer
self.recv_buf = [] # recv buffer
self.pend_buf = '' # send pending
self.state = NET_STATE_CLOSED
self.errd = [ errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK ]
self.conn = ( errno.EISCONN, 10057, 10053 )
self.errc = 0
self.ipv6 = False
self.eintr = ()
if 'EINTR' in errno.__dict__:
self.eintr = (errno.__dict__['EINTR'],)
if 'WSAEWOULDBLOCK' in errno.__dict__:
self.errd.append(errno.WSAEWOULDBLOCK)
self.errd = tuple(self.errd)
self.timeout = 0
self.timecon = 0
示例2: connectRemotes
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def connectRemotes(self):
for remote in self.remoteAddrs:
if remote['socket']:
continue
# Attempt reconnection at most once every N seconds
if remote['connectFailure'] and remote['connectFailure'] > time.time()-self.remoteRetry:
return
remoteConnection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
remoteConnection.setblocking(0)
self.logger.info('REMOTE: Connecting to remote %s' % remote['addr'])
remote['connecting'] = True
try:
remoteConnection.connect((remote['addr'], self.remotePort))
except socket.error as e:
if e.errno == errno.EINPROGRESS:
remote['socket'] = remoteConnection
else:
remote['connecting'] = False
remote['connectFailure'] = time.time()
示例3: _socketpair_compat
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def _socketpair_compat():
"""TCP/IP socketpair including Windows support"""
listensock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_IP)
listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listensock.bind(("127.0.0.1", 0))
listensock.listen(1)
iface, port = listensock.getsockname()
sock1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_IP)
sock1.setblocking(0)
try:
sock1.connect(("localhost", port))
except socket.error as err:
if err.errno != errno.EINPROGRESS and err.errno != errno.EWOULDBLOCK and err.errno != EAGAIN:
raise
sock2, address = listensock.accept()
sock2.setblocking(0)
listensock.close()
return (sock1, sock2)
示例4: _connect
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [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,))
示例5: connect
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def connect(self):
while True:
errno = self.sock.connect_ex(self.addr)
if not errno:
# connected immediately.
break
elif errno == EINPROGRESS:
# will be connected.
break
elif errno == ENOENT:
# no such socket file.
self.create_connection(self.failover_interval)
return
else:
raise ValueError('Unexpected socket errno: %d' % errno)
self.event_loop.watch_file(self.sock.fileno(), self.handle)
示例6: __init__
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def __init__(self, addr, callback):
host, port = addr.split(':', 2)
port = int(port)
self._addr = (host, port)
self._sock = socket.socket()
self._sock.setblocking(0)
self.connected = False
try:
self._sock.connect(self._addr)
except socket.error as e:
if e.errno != errno.EAGAIN and e.errno != errno.EINPROGRESS:
raise
self._parser = HttpParser()
self._callback = callback
self._stream_id = None
self._request = callback.gen_request()
self._response = b''
示例7: asyncConnect
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def asyncConnect(self, address, callback):
if (self.__acceptCallback):
raise AsyncException('Accept already in progress')
if (self.__connectCallback):
raise AsyncException('Connect already in progress')
if (self.__readCallback):
raise AsyncException('Read already in progress')
if (self.__writeAllCallback):
raise AsyncException('Write all already in progress')
if (self.__closed):
raise AsyncException('AsyncSocket closed')
err = self.__socket.connect_ex(address)
if err in (errno.EINPROGRESS, errno.EWOULDBLOCK):
self.__connectCallback = callback
self.__asyncIOService.registerAsyncSocketForWrite(self)
else:
self.__asyncIOService.invokeLater(
functools.partial(callback, err = err))
示例8: open
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def open(name, dscp=DSCP_DEFAULT):
"""Attempts to connect a stream to a remote peer. 'name' is a
connection name in the form "TYPE:ARGS", where TYPE is an active stream
class's name and ARGS are stream class-specific. Currently the only
supported TYPEs are "unix" and "tcp".
Returns (error, stream): on success 'error' is 0 and 'stream' is the
new Stream, on failure 'error' is a positive errno value and 'stream'
is None.
Never returns errno.EAGAIN or errno.EINPROGRESS. Instead, returns 0
and a new Stream. The connect() method can be used to check for
successful connection completion."""
cls = Stream._find_method(name)
if not cls:
return errno.EAFNOSUPPORT, None
suffix = name.split(":", 1)[1]
error, sock = cls._open(suffix, dscp)
if error:
return error, None
else:
status = ovs.socket_util.check_connection_completion(sock)
return 0, Stream(sock, name, status)
示例9: open_block
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def open_block((error, stream)):
"""Blocks until a Stream completes its connection attempt, either
succeeding or failing. (error, stream) should be the tuple returned by
Stream.open(). Returns a tuple of the same form.
Typical usage:
error, stream = Stream.open_block(Stream.open("unix:/tmp/socket"))"""
if not error:
while True:
error = stream.connect()
if error != errno.EAGAIN:
break
stream.run()
poller = ovs.poller.Poller()
stream.run_wait(poller)
stream.connect_wait(poller)
poller.block()
assert error != errno.EINPROGRESS
if error and stream:
stream.close()
stream = None
return error, stream
示例10: _socketpair_compat
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def _socketpair_compat():
"""TCP/IP socketpair including Windows support"""
listensock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_IP)
listensock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listensock.bind(("127.0.0.1", 0))
listensock.listen(1)
iface, port = listensock.getsockname()
sock1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_IP)
sock1.setblocking(0)
try:
sock1.connect(("127.0.0.1", port))
except socket.error as err:
if err.errno != errno.EINPROGRESS and err.errno != errno.EWOULDBLOCK and err.errno != EAGAIN:
raise
sock2, address = listensock.accept()
sock2.setblocking(0)
listensock.close()
return (sock1, sock2)
示例11: connect
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def connect(self, address):
"""
Try to make an actual connection.
:return: True if connected
"""
sock = self._connectors[address]
err = sock.connect()
self.poller.register(sock)
self._sock_by_fd[sock.fileno()] = sock
self._socks_waiting_to_connect.add(sock)
if err in (0, errno.EISCONN):
self.handle_connect(sock)
return True
elif err in (errno.ECONNREFUSED, errno.ENETUNREACH):
self.handle_conn_refused(sock)
elif err not in (errno.EINPROGRESS, errno.EWOULDBLOCK):
raise socket.error(err, errno.errorcode[err])
return False
##########################################################
示例12: _send_control_data
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def _send_control_data(self, data):
if self._control_client_addr:
try:
self._control_socket.sendto(data, self._control_client_addr)
except (socket.error, OSError, IOError) as e:
error_no = eventloop.errno_from_exception(e)
if error_no in (errno.EAGAIN, errno.EINPROGRESS,
errno.EWOULDBLOCK):
return
else:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
示例13: _write_to_sock
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def _write_to_sock(self, data, sock):
# write data to sock
# if only some of the data are written, put remaining in the buffer
# and update the stream to wait for writing
if not data or not sock:
return False
uncomplete = False
try:
l = len(data)
s = sock.send(data)
if s < l:
data = data[s:]
uncomplete = True
except (OSError, IOError) as e:
error_no = eventloop.errno_from_exception(e)
if error_no in (errno.EAGAIN, errno.EINPROGRESS,
errno.EWOULDBLOCK):
uncomplete = True
else:
shell.print_exception(e)
self.destroy()
return False
if uncomplete:
if sock == self._local_sock:
self._data_to_write_to_local.append(data)
self._update_stream(STREAM_DOWN, WAIT_STATUS_WRITING)
elif sock == self._remote_sock:
self._data_to_write_to_remote.append(data)
self._update_stream(STREAM_UP, WAIT_STATUS_WRITING)
else:
logging.error('write_all_to_sock:unknown socket')
else:
if sock == self._local_sock:
self._update_stream(STREAM_DOWN, WAIT_STATUS_READING)
elif sock == self._remote_sock:
self._update_stream(STREAM_UP, WAIT_STATUS_READING)
else:
logging.error('write_all_to_sock:unknown socket')
return True
示例14: _handle_stage_connecting
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [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()
示例15: handle_event
# 需要导入模块: import errno [as 别名]
# 或者: from errno import EINPROGRESS [as 别名]
def handle_event(self, sock, fd, event):
# handle events and dispatch to handlers
if sock:
logging.log(shell.VERBOSE_LEVEL, 'fd %d %s', fd,
eventloop.EVENT_NAMES.get(event, event))
if sock == self._server_socket:
if event & eventloop.POLL_ERR:
# TODO
raise Exception('server_socket error')
try:
logging.debug('accept')
conn = self._server_socket.accept()
TCPRelayHandler(self, self._fd_to_handlers,
self._eventloop, conn[0], self._config,
self._dns_resolver, self._is_local)
except (OSError, IOError) as e:
error_no = eventloop.errno_from_exception(e)
if error_no in (errno.EAGAIN, errno.EINPROGRESS,
errno.EWOULDBLOCK):
return
else:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
else:
if sock:
handler = self._fd_to_handlers.get(fd, None)
if handler:
handler.handle_event(sock, event)
else:
logging.warn('poll removed fd')