本文整理匯總了Python中eventsocket.EventSocket.setsockopt方法的典型用法代碼示例。如果您正苦於以下問題:Python EventSocket.setsockopt方法的具體用法?Python EventSocket.setsockopt怎麽用?Python EventSocket.setsockopt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類eventsocket.EventSocket
的用法示例。
在下文中一共展示了EventSocket.setsockopt方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Connection
# 需要導入模塊: from eventsocket import EventSocket [as 別名]
# 或者: from eventsocket.EventSocket import setsockopt [as 別名]
#.........這裏部分代碼省略.........
'''Number of frames written in the lifetime of this connection.'''
return self._frames_written
@property
def close_info(self):
'''Return dict with information on why this connection is closed. Will
return None if the connections is open.'''
return self._close_info if self._closed else None
def reconnect(self):
'''Reconnect to the configured host and port.'''
self._strategy.connect()
def connect(self, host, port):
'''
Connect to a host and port. Can be called directly, or is called by the
strategy as it tries to find and connect to hosts.
'''
# Clear the connect state immediately since we're no longer connected
# at this point.
self._connected = False
# NOTE: purposefully leave output_frame_buffer alone so that pending writes can
# still occur. this allows the reconnect to occur silently without
# completely breaking any pending data on, say, a channel that was just
# opened.
self._sock = EventSocket( read_cb=self._sock_read_cb,
close_cb=self._sock_close_cb, error_cb=self._sock_error_cb,
debug=self._debug, logger=self._logger )
self._sock.settimeout( self._connect_timeout )
if self._sock_opts:
for k,v in self._sock_opts.iteritems():
family,type = k
self._sock.setsockopt(family, type, v)
self._sock.connect( (host,port) )
self._sock.setblocking( False )
# Only after the socket has connected do we clear this state; closed must
# be False so that writes can be buffered in writePacket(). The closed
# state might have been set to True due to a socket error or a redirect.
self._host = "%s:%d"%(host,port)
self._closed = False
self._close_info = {
'reply_code' : 0,
'reply_text' : 'failed to connect to %s'%(self._host),
'class_id' : 0,
'method_id' : 0
}
self._sock.write( PROTOCOL_HEADER )
def disconnect(self):
'''
Disconnect from the current host, but otherwise leave this object "open"
so that it can be reconnected.
'''
self._connected = False
if self._sock!=None:
self._sock.close_cb = None
try:
self._sock.close()
except:
self.logger.error("Failed to disconnect socket to %s", self._host, exc_info=True)
self._sock = None
def add_reconnect_callback(self, callback):