本文整理汇总了Python中buffer.Buffer.capacity方法的典型用法代码示例。如果您正苦于以下问题:Python Buffer.capacity方法的具体用法?Python Buffer.capacity怎么用?Python Buffer.capacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类buffer.Buffer
的用法示例。
在下文中一共展示了Buffer.capacity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from buffer import Buffer [as 别名]
# 或者: from buffer.Buffer import capacity [as 别名]
#.........这里部分代码省略.........
else:
logging.error("_rawSend error %s", str(e.args[0]))
sent = -1
return sent
def close(self):
if self.__sock is None:
return
try:
self.__sock.shutdown(socket.SHUT_WR)
self.__sock.close()
self.__sock = None
if self.__onDisconnectCallback is not None:
self.__onDisconnectCallback(self)
except socket.error as serr:
pass
def onConnect(self):
if self.__onConnectCallback is not None:
self.__onConnectCallback(self)
def onError(self):
self.close()
def onReadable(self):
while True:
self.__recvbuf.assureSpace(4 * 1024)
data, offset = self.__recvbuf.data()
try:
mv = memoryview(data)
recved = self.__sock.recv_into(mv[offset:], self.__recvbuf.capacity() - offset)
except socket.error as serr:
if serr.errno == os.errno.EAGAIN:
#logging.debug("recv EAGAIN.")
return True
else:
logging.error("recv error %s", str(serr.errno))
raise
if recved > 0:
logging.info("recv %d", recved)
self.__recvbuf.produce(recved)
while not self.__recvbuf.empty():
data, len = self.__recvbuf.data()
mv = memoryview(data[:len])
consumed = self.__msgCallback(self, mv)
if consumed < 0:
self.close()
elif consumed == 0:
break
else:
self.__recvbuf.consume(consumed)
else:
return False
raise RuntimeError("never here")
def onWritable(self):
from ioloop import IOLoop
if not self.__shouldPollWrite:
self.__loop.modify(self, IOLoop.READ_EVENT)
return True
if self.__sendbuf.empty():
self.__shouldPollWrite = False
self.__loop.modify(self, IOLoop.READ_EVENT)
return True
data, len = self.__sendbuf.data()
mvSendData = memoryview(data[:len])
sent = self._rawSend(mvSendData)
if sent < 0:
return False
self.__sendbuf.consume(sent)
if not self.__shouldPollWrite or self.__sendbuf.empty():
self.__loop.modify(self, IOLoop.READ_EVENT)
return True
def newFuture(self):
# add new future to conn's pending list
fut = Future()
self.__futures.append(fut)
return fut
def resolveAndPopFuture(self, value):
fut = self.__futures.pop(0)
fut.set_result(value)