Skip to content

Commit

Permalink
wrap socket error to tidevice.SocketError
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Jan 23, 2024
1 parent 12f4bae commit dfa7079
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 2 additions & 4 deletions tidevice/_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,7 @@ def _launch_wda_app(self,
conn = self.connect_instruments()
channel = conn.make_channel(InstrumentsService.ProcessControl)

conn.call_message(channel, "processIdentifierForBundleIdentifier:",
[bundle_id])

conn.call_message(channel, "processIdentifierForBundleIdentifier:", [bundle_id])
# launch app
identifier = "launchSuspendedProcessWithDevicePath:bundleIdentifier:environment:arguments:options:"
app_path = app_info['Path']
Expand Down Expand Up @@ -1111,7 +1109,7 @@ def _record_test_result_callback(m: DTXMessage):

def _ready_with_caps_callback(m: DTXMessage):
x2.send_dtx_message(m.channel_id,
payload=DTXPayload.build_other(0x03, xctest_configuration),
payload=DTXPayload.build_other(0x03),
message_id=m.message_id)

x2.register_callback('_XCT_testRunnerReadyWithCapabilities:', _ready_with_caps_callback)
Expand Down
18 changes: 12 additions & 6 deletions tidevice/_safe_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,19 @@ def __init__(self, addr: Union[str, typing.Tuple[str, int], socket.socket,
addr: can be /var/run/usbmuxd or localhost:27015 or (localhost, 27015)
"""
self._id = acquire_uid()
self._sock = None
self._dup_sock = None # keep original sock when switch_to_ssl
self._name = None

try:
self._sock = self._connect(addr)
except Exception as e:
raise SocketError("socket connect error") from e

self._finalizer = weakref.finalize(self, self._cleanup)

def _connect(self, addr: Union[str, typing.Tuple[str, int], socket.socket, Any]):
if isinstance(addr, socket.socket):
self._sock = addr
return addr
else:
if isinstance(addr, str):
if ':' in addr:
Expand All @@ -71,10 +78,9 @@ def __init__(self, addr: Union[str, typing.Tuple[str, int], socket.socket,
raise SocketError("socket unix:{} unable to connect".format(addr))
else:
family = socket.AF_INET
self._sock = socket.socket(family, socket.SOCK_STREAM)
self._sock.connect(addr)

self._finalizer = weakref.finalize(self, self._cleanup)
sock = socket.socket(family, socket.SOCK_STREAM)
sock.connect(addr)
return sock

def _cleanup(self):
release_uid(self.id)
Expand Down

0 comments on commit dfa7079

Please sign in to comment.