Skip to content

Commit

Permalink
optimize connect return
Browse files Browse the repository at this point in the history
  • Loading branch information
aoliaoaoaojiao committed Dec 2, 2022
1 parent def21ac commit d0e5002
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,36 @@ func newDevice(client *libimobiledevice.UsbmuxClient, properties DevicePropertie
}
}

func NewRemoteConnect(ip string, port int, timeout int) *device {
func NewRemoteConnect(ip string, port int, timeout int) (*device, error) {
client, err := libimobiledevice.NewUsbmuxClient(fmt.Sprintf("%s:%d", ip, port), time.Duration(timeout)*time.Second)
if err != nil {
log.Panic(err)
return nil, err
}

clientConnectInit(client.InnerConn())

devicePropertiesPacket, err := client.ReceivePacket()
if err != nil {
log.Panic(err)
return nil, err
}
var properties = &DeviceProperties{}
err = devicePropertiesPacket.Unmarshal(properties)
if err != nil {
log.Panic(err)
return nil, err
}
buffer := new(bytes.Buffer)
data, err1 := client.InnerConn().Read(4)
if err1 != nil {
log.Panic(err1)
return nil, err
}
buffer.Write(data)
var remoteLockdownPort uint32
if err = binary.Read(buffer, binary.LittleEndian, &remoteLockdownPort); err != nil {
log.Panic(err)
return nil, err
}
dev := newDevice(client, *properties)
dev.remoteAddr = fmt.Sprintf("%s:%d", ip, remoteLockdownPort)
return dev
return dev, nil
}

type device struct {
Expand Down
6 changes: 3 additions & 3 deletions device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func Test_device_share(t *testing.T) {

func Test_device_connect(t *testing.T) {
SetDebug(true, true)
remoteDev := NewRemoteConnect("127.0.0.1", 9123, 30)
remoteDev, _ := NewRemoteConnect("127.0.0.1", 9123, 30)
data, err := remoteDev.GetValue("", "ProductVersion")
if err != nil {
log.Panic(err)
Expand All @@ -195,7 +195,7 @@ func Test_device_connect(t *testing.T) {

func TestMockPerfdUser1(t *testing.T) {
//SetDebug(true, true)
remoteDev := NewRemoteConnect("127.0.0.1", 9123, 30)
remoteDev, _ := NewRemoteConnect("127.0.0.1", 9123, 30)
data, err := remoteDev.PerfStart(
WithPerfSystemCPU(true),
WithPerfSystemMem(true),
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestMockPerfdUser1(t *testing.T) {

func TestMockPerfdUser2(t *testing.T) {
//SetDebug(true, true)
remoteDev := NewRemoteConnect("127.0.0.1", 9123, 30)
remoteDev, _ := NewRemoteConnect("127.0.0.1", 9123, 30)
data, err := remoteDev.PerfStart(
WithPerfSystemCPU(true),
WithPerfSystemMem(true),
Expand Down

0 comments on commit d0e5002

Please sign in to comment.