From 72ee4e13684ac06b9f2c457669db6fdf60821b18 Mon Sep 17 00:00:00 2001 From: sam80180 Date: Sat, 4 May 2024 01:16:43 +0800 Subject: [PATCH] fix: stop loop when usbmuxd is down --- usbmux.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/usbmux.go b/usbmux.go index 6050536..74c9bd6 100644 --- a/usbmux.go +++ b/usbmux.go @@ -95,7 +95,10 @@ func (um *usbmux) Listen(devNotifier chan Device) (context.CancelFunc, error) { select { case <-ctx.Done(): return - case baseDev := <-baseDevNotifier: + case baseDev, ok := <-baseDevNotifier: + if !ok { + return + } if baseDev.MessageType != libimobiledevice.MessageTypeDeviceAdd { baseDev.Properties.DeviceID = baseDev.DeviceID } @@ -133,7 +136,7 @@ func (um *usbmux) listen(devNotifier chan libimobiledevice.BaseDevice) (ctx cont default: var respPkt libimobiledevice.Packet if respPkt, err = um.client.ReceivePacket(); err != nil { - break + return } var replyDevice libimobiledevice.BaseDevice