当前位置: 首页>>代码示例>>Python>>正文


Python EventSocket.setsockopt方法代码示例

本文整理汇总了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):
开发者ID:carriercomm,项目名称:haigha,代码行数:70,代码来源:connection.py


注:本文中的eventsocket.EventSocket.setsockopt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。