]>
git.saurik.com Git - apple/xnu.git/blob - tools/lldbmacros/usertaskdebugging/interface.py
5 class Interface(object):
6 """Basic communication interface."""
7 def __init__(self
, host_cfg
, portnum
):
8 super(Interface
, self
).__init
__()
9 self
.host_cfg
= host_cfg
10 self
.portnum
= portnum
13 self
.isblocking
= True
14 logging
.debug("created %s" % str(self
))
17 self
.socket
= socket
.socket(socket
.AF_INET
, socket
.SOCK_STREAM
)
18 self
.socket
.setsockopt(socket
.SOL_SOCKET
, socket
.SO_REUSEADDR
, 1)
19 self
.socket
.bind((self
.host_cfg
, self
.portnum
))
20 logging
.debug("Initializing network interface for communication host: %s:%d", self
.host_cfg
, self
.portnum
)
23 while num_retries
> 0:
24 ra
,wa
,ea
= select
.select([self
.socket
], [], [], 30)
27 logging
.warning("timeout: select returned empty list. retrying..")
29 self
.connection
, addr
= self
.socket
.accept()
30 logging
.info("Connected to client from %s" % str(addr
))
32 logging
.error("Failed to connect. Exiting after multiple attempts.")
37 #BUG TODO make this unblocking soon
38 #logging.warn("blocking read bug")
39 self
.connection
.settimeout(15)
40 self
.isblocking
= False
43 r_bytes
= self
.connection
.recv(self
.pkt_size
)
45 #logging.debug("Found exception in recv. %s " % (str(e)))
50 def write(self
, bytes):
51 if not self
.isblocking
:
52 self
.connection
.setblocking(1)
53 self
.isblocking
= True
54 return self
.connection
.send(bytes)
58 logging
.debug('closing connection.')
59 self
.connection
.close()
63 return "interface: %s %d" % (self
.host_cfg
, self
.portnum
)