本文整理汇总了Python中thrift.transport.TSocket.TSocket.setHandle方法的典型用法代码示例。如果您正苦于以下问题:Python TSocket.setHandle方法的具体用法?Python TSocket.setHandle怎么用?Python TSocket.setHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thrift.transport.TSocket.TSocket
的用法示例。
在下文中一共展示了TSocket.setHandle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serveClient
# 需要导入模块: from thrift.transport.TSocket import TSocket [as 别名]
# 或者: from thrift.transport.TSocket.TSocket import setHandle [as 别名]
def serveClient(self, socket, address):
"""Process input/output from a client for as long as possible"""
client = TSocket()
client.setHandle(socket)
self.peerName = client.getPeerName()
thread_info = current_thread()
itrans = self.inputTransportFactory.getTransport(client)
otrans = self.outputTransportFactory.getTransport(client)
iprot = self.inputProtocolFactory.getProtocol(itrans)
if isinstance(self.inputProtocolFactory, THeaderProtocolFactory):
oprot = iprot
else:
oprot = self.outputProtocolFactory.getProtocol(otrans)
try:
while True:
if isinstance(getattr(self.processor._handler, 'peerName', None), dict):
self.processor._handler.peerName[thread_info] = client.getPeerName()
else:
self.processor._handler.peerName = {thread_info: client.getPeerName()}
self.processor.process(iprot, oprot)
except TTransportException as tx:
pass
except Exception as x:
self.logger.error('[%s]', x, extra={'clientip': client.getPeerName()})
itrans.close()
otrans.close()
示例2: TLateInitSSLSocket
# 需要导入模块: from thrift.transport.TSocket import TSocket [as 别名]
# 或者: from thrift.transport.TSocket.TSocket import setHandle [as 别名]
class TLateInitSSLSocket(TTransportBase):
def __init__(self, handle):
self.handle = handle
self.socket = None
def getSocket(self):
if self.socket is None:
self.handle.do_handshake()
self.socket = TSocket()
self.socket.setHandle(self.handle)
return self.socket
def isOpen(self):
return self.getSocket().isOpen()
def setTimeout(self, ms):
return self.getSocket().setTimeout(ms)
def read(self, sz):
return self.getSocket().read(sz)
def write(self, sz):
return self.getSocket().write(sz)
def flush(self):
return self.getSocket().flush()
def close(self):
if self.socket is None:
self.handle.close()
else:
return self.getSocket().close()
示例3: handle_stream
# 需要导入模块: from thrift.transport.TSocket import TSocket [as 别名]
# 或者: from thrift.transport.TSocket.TSocket import setHandle [as 别名]
def handle_stream(self, sock, address):
tsock = TSocket()
tsock.setHandle(sock)
itrans = self.itrans.getTransport(tsock)
otrans = self.otrans.getTransport(tsock)
iprot = self.iprot.getProtocol(itrans)
oprot = self.oprot.getProtocol(otrans)
try:
while True:
self.processor.process(iprot, oprot)
except TTransportException, ex:
pass
示例4: handle
# 需要导入模块: from thrift.transport.TSocket import TSocket [as 别名]
# 或者: from thrift.transport.TSocket.TSocket import setHandle [as 别名]
def handle(self, client_socket, _):
client = TSocket()
client.setHandle(client_socket)
trans = self.transport_factory.getTransport(client)
prot = self.protocol_factory.getProtocol(trans)
server_context = TRpcConnectionContext(client, prot, prot)
try:
while self.started:
self.processor.process(prot, prot, server_context)
except TTransportException:
pass
finally:
trans.close()
示例5: serveClient
# 需要导入模块: from thrift.transport.TSocket import TSocket [as 别名]
# 或者: from thrift.transport.TSocket.TSocket import setHandle [as 别名]
def serveClient(self, socket, address):
"""Process input/output from a client for as long as possible"""
client = TSocket()
client.setHandle(socket)
itrans = self.inputTransportFactory.getTransport(client)
otrans = self.outputTransportFactory.getTransport(client)
iprot = self.inputProtocolFactory.getProtocol(itrans)
if isinstance(self.inputProtocolFactory, THeaderProtocolFactory):
oprot = iprot
else:
oprot = self.outputProtocolFactory.getProtocol(otrans)
try:
while True:
self.processor.process(iprot, oprot)
except TTransportException as tx:
pass
except Exception as x:
logging.exception(x)
itrans.close()
otrans.close()
示例6: accept
# 需要导入模块: from thrift.transport.TSocket import TSocket [as 别名]
# 或者: from thrift.transport.TSocket.TSocket import setHandle [as 别名]
def accept(self):
while True:
plain_client, addr = self.handle.accept()
#print self.allowed_ips, addr[0]
if self.allowed_ips and addr[0] not in self.allowed_ips:
logging.warn ("client %s is not allowed to connect" % (addr[0]))
plain_client.close()
continue
try:
client = ssl.wrap_socket(plain_client, certfile=self.certfile,
server_side=True, ssl_version=self.SSL_VERSION)
except (ssl.SSLError), e:
# failed handshake/ssl wrap, close socket to client
plain_client.close()
logging.exception (e)
continue
result = TSocket()
result.setHandle(client)
return result