本文整理汇总了Python中interface.Interface.read方法的典型用法代码示例。如果您正苦于以下问题:Python Interface.read方法的具体用法?Python Interface.read怎么用?Python Interface.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interface.Interface
的用法示例。
在下文中一共展示了Interface.read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GDBServer
# 需要导入模块: from interface import Interface [as 别名]
# 或者: from interface.Interface import read [as 别名]
class GDBServer(object):
"""instance of gdbserver"""
def __init__(self, backing_instance):
super(GDBServer, self).__init__()
self.process = backing_instance
self.portnum = random.randint(2000, 8000)
logging.info("Starting gdb server for localhost:%d" % self.portnum)
self.conn = Interface("localhost", self.portnum)
self.version_string = "name:kdbserver;version:0.1"
def run(self):
if not self.conn.connect():
logging.critical("No client connected. Bailing.")
return False
logging.debug("Starting gdb server.")
while True:
# loop for running the server.
# read command
readBytes = ""
while True:
try:
p_bytes = self.conn.read()
except Exception, e:
logging.warn("found exception in read %s" % (str(e)))
logging.debug("currentbytes: %s" % readBytes)
readBytes = ""
break
readBytes += p_bytes
p_begin = readBytes.find("$")
p_end = readBytes.find("#")
if p_begin >= 0 and p_end >= 0 and p_end > p_begin:
break
# if empty message or acks just ignore
if readBytes in ("", "+"):
logging.debug("ignoring message: %s" % readBytes)
continue
req_msg = rsprotocol.Message.fromRSPByteData(readBytes)
resp = self.handleMessage(req_msg)
# in case resp is to detach
if resp is None:
return True
for r_msg in resp:
logging.debug("response: %s" % r_msg.getRSPByteData())
self.conn.write(r_msg.getRSPByteData())
return True