Skip to content

Commit 14b355c

Browse files
authored
Merge pull request #1422 from doronz88/bugfix/tunnel-service-bugs
Bugfix/tunnel service bugs
2 parents 02f68d1 + 6b727e3 commit 14b355c

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

pymobiledevice3/remote/tunnel_service.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from ssl import VerifyMode
2222
from typing import Optional, TextIO, cast
2323

24-
import aiofiles
2524
from construct import Const, Container
2625
from construct import Enum as ConstructEnum
2726
from construct import GreedyBytes, GreedyRange, Int8ul, Int16ub, Int64ul, Prefixed, Struct
@@ -161,12 +160,11 @@ async def tun_read_task(self) -> None:
161160
read_size = self.tun.mtu + len(LOOPBACK_HEADER)
162161
try:
163162
if sys.platform != 'win32':
164-
async with aiofiles.open(self.tun.fileno(), 'rb', opener=lambda path, flags: path, buffering=0) as f:
165-
while True:
166-
packet = await f.read(read_size)
167-
assert packet.startswith(LOOPBACK_HEADER)
168-
packet = packet[len(LOOPBACK_HEADER):]
169-
await self.send_packet_to_device(packet)
163+
while True:
164+
packet = await asyncio.to_thread(self.tun.read, read_size)
165+
assert packet.startswith(LOOPBACK_HEADER)
166+
packet = packet[len(LOOPBACK_HEADER):]
167+
await self.send_packet_to_device(packet)
170168
else:
171169
while True:
172170
packet = await self.tun.async_read()
@@ -311,13 +309,13 @@ async def stop_tunnel(self) -> None:
311309
self._sock_read_task.cancel()
312310
with suppress(CancelledError):
313311
await self._sock_read_task
312+
await super().stop_tunnel()
314313
if not self._writer.is_closing():
315314
self._writer.close()
316315
try:
317316
await self._writer.wait_closed()
318317
except OSError:
319318
pass
320-
await super().stop_tunnel()
321319

322320

323321
@dataclasses.dataclass

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ developer_disk_image>=0.0.2
3737
opack2
3838
psutil
3939
pytun-pmd3>=2.1.0
40-
aiofiles
4140
prompt_toolkit
4241
sslpsk-pmd3>=1.0.3;python_version<'3.13'
4342
python-pcapng>=2.1.1

0 commit comments

Comments
 (0)