diff options
| -rw-r--r-- | iphone.c | 2 | ||||
| -rw-r--r-- | main.c | 11 | ||||
| -rw-r--r-- | sock_stuff.c | 4 |
3 files changed, 8 insertions, 9 deletions
| @@ -1086,7 +1086,7 @@ int iphone_mux_pullbulk(iphone_device_t phone) | |||
| 1086 | // start the cursor off just ahead of the leftover. | 1086 | // start the cursor off just ahead of the leftover. |
| 1087 | char* cursor = &phone->usbReceive.buffer[phone->usbReceive.leftover]; | 1087 | char* cursor = &phone->usbReceive.buffer[phone->usbReceive.leftover]; |
| 1088 | // pull in content, note that the amount we can pull is capacity minus leftover | 1088 | // pull in content, note that the amount we can pull is capacity minus leftover |
| 1089 | int readlen = recv_from_phone_timeout(phone, cursor, phone->usbReceive.capacity - phone->usbReceive.leftover, 5000); | 1089 | int readlen = recv_from_phone_timeout(phone, cursor, phone->usbReceive.capacity - phone->usbReceive.leftover, 3000); |
| 1090 | if (readlen < 0) { | 1090 | if (readlen < 0) { |
| 1091 | res = readlen; | 1091 | res = readlen; |
| 1092 | //fprintf(stderr, "recv_from_phone_timeout gave us an error.\n"); | 1092 | //fprintf(stderr, "recv_from_phone_timeout gave us an error.\n"); |
| @@ -605,11 +605,11 @@ connect: | |||
| 605 | if (verbose >= 3) fprintf(stderr, "%s: Setting up connection to usb device #%d on port %d\n", __func__, c_req->device_id, ntohs(c_req->tcp_dport)); | 605 | if (verbose >= 3) fprintf(stderr, "%s: Setting up connection to usb device #%d on port %d\n", __func__, c_req->device_id, ntohs(c_req->tcp_dport)); |
| 606 | 606 | ||
| 607 | // find the device, and open usb connection | 607 | // find the device, and open usb connection |
| 608 | pthread_mutex_lock(&usbmux_mutex); | ||
| 608 | phone = NULL; | 609 | phone = NULL; |
| 609 | cur_dev = NULL; | 610 | cur_dev = NULL; |
| 610 | // first check if we already have an open connection | 611 | // first check if we already have an open connection |
| 611 | if (devices) { | 612 | if (devices) { |
| 612 | pthread_mutex_lock(&usbmux_mutex); | ||
| 613 | for (i = 0; i < device_count; i++) { | 613 | for (i = 0; i < device_count; i++) { |
| 614 | if (devices[i]) { | 614 | if (devices[i]) { |
| 615 | if (devices[i]->device_id == c_req->device_id) { | 615 | if (devices[i]->device_id == c_req->device_id) { |
| @@ -620,7 +620,6 @@ connect: | |||
| 620 | } | 620 | } |
| 621 | } | 621 | } |
| 622 | } | 622 | } |
| 623 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 624 | } | 623 | } |
| 625 | if (!phone) { | 624 | if (!phone) { |
| 626 | // if not found, make a new connection | 625 | // if not found, make a new connection |
| @@ -629,6 +628,7 @@ connect: | |||
| 629 | pthread_mutex_lock(&usb_mutex); | 628 | pthread_mutex_lock(&usb_mutex); |
| 630 | if (iphone_get_specific_device(0, c_req->device_id, &phone) != IPHONE_E_SUCCESS) { | 629 | if (iphone_get_specific_device(0, c_req->device_id, &phone) != IPHONE_E_SUCCESS) { |
| 631 | pthread_mutex_unlock(&usb_mutex); | 630 | pthread_mutex_unlock(&usb_mutex); |
| 631 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 632 | if (verbose >= 1) fprintf(stderr, "%s: device_id %d could not be opened\n", __func__, c_req->device_id); | 632 | if (verbose >= 1) fprintf(stderr, "%s: device_id %d could not be opened\n", __func__, c_req->device_id); |
| 633 | usbmuxd_send_result(cdata->socket, c_req->header.tag, ENODEV); | 633 | usbmuxd_send_result(cdata->socket, c_req->header.tag, ENODEV); |
| 634 | goto leave; | 634 | goto leave; |
| @@ -636,7 +636,6 @@ connect: | |||
| 636 | pthread_mutex_unlock(&usb_mutex); | 636 | pthread_mutex_unlock(&usb_mutex); |
| 637 | 637 | ||
| 638 | // create device object | 638 | // create device object |
| 639 | pthread_mutex_lock(&usbmux_mutex); | ||
| 640 | if (verbose >= 3) fprintf(stderr, "%s: add to device list\n", __func__); | 639 | if (verbose >= 3) fprintf(stderr, "%s: add to device list\n", __func__); |
| 641 | cur_dev = (struct device_info*)malloc(sizeof(struct device_info)); | 640 | cur_dev = (struct device_info*)malloc(sizeof(struct device_info)); |
| 642 | memset(cur_dev, 0, sizeof(struct device_info)); | 641 | memset(cur_dev, 0, sizeof(struct device_info)); |
| @@ -655,10 +654,10 @@ connect: | |||
| 655 | devices[device_count] = cur_dev; | 654 | devices[device_count] = cur_dev; |
| 656 | device_count++; | 655 | device_count++; |
| 657 | } | 656 | } |
| 658 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 659 | } else { | 657 | } else { |
| 660 | if (verbose >= 3) fprintf(stderr, "%s: reusing usb connection, device_id=%d\n", __func__, c_req->device_id); | 658 | if (verbose >= 3) fprintf(stderr, "%s: reusing usb connection, device_id=%d\n", __func__, c_req->device_id); |
| 661 | } | 659 | } |
| 660 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 662 | 661 | ||
| 663 | // setup connection to iPhone/iPod | 662 | // setup connection to iPhone/iPod |
| 664 | // pthread_mutex_lock(&usbmux_mutex); | 663 | // pthread_mutex_lock(&usbmux_mutex); |
| @@ -712,6 +711,7 @@ leave: | |||
| 712 | 711 | ||
| 713 | // this has to be freed only if it's not in use anymore as it closes | 712 | // this has to be freed only if it's not in use anymore as it closes |
| 714 | // the USB connection | 713 | // the USB connection |
| 714 | pthread_mutex_lock(&usbmux_mutex); | ||
| 715 | if (cur_dev) { | 715 | if (cur_dev) { |
| 716 | pthread_mutex_lock(&cur_dev->mutex); | 716 | pthread_mutex_lock(&cur_dev->mutex); |
| 717 | if (cur_dev->use_count > 1) { | 717 | if (cur_dev->use_count > 1) { |
| @@ -733,7 +733,6 @@ leave: | |||
| 733 | pthread_mutex_destroy(&cur_dev->mutex); | 733 | pthread_mutex_destroy(&cur_dev->mutex); |
| 734 | free(cur_dev); | 734 | free(cur_dev); |
| 735 | cur_dev = NULL; | 735 | cur_dev = NULL; |
| 736 | pthread_mutex_lock(&usbmux_mutex); | ||
| 737 | if (device_count > 1) { | 736 | if (device_count > 1) { |
| 738 | struct device_info **newlist; | 737 | struct device_info **newlist; |
| 739 | int j; | 738 | int j; |
| @@ -752,9 +751,9 @@ leave: | |||
| 752 | devices = NULL; | 751 | devices = NULL; |
| 753 | device_count = 0; | 752 | device_count = 0; |
| 754 | } | 753 | } |
| 755 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 756 | } | 754 | } |
| 757 | } | 755 | } |
| 756 | pthread_mutex_unlock(&usbmux_mutex); | ||
| 758 | 757 | ||
| 759 | cdata->dead = 1; | 758 | cdata->dead = 1; |
| 760 | close(cdata->socket); | 759 | close(cdata->socket); |
diff --git a/sock_stuff.c b/sock_stuff.c index 78249e6..8a06135 100644 --- a/sock_stuff.c +++ b/sock_stuff.c | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #include <arpa/inet.h> | 11 | #include <arpa/inet.h> |
| 12 | #include "sock_stuff.h" | 12 | #include "sock_stuff.h" |
| 13 | 13 | ||
| 14 | #define RECV_TIMEOUT 10000 | 14 | #define RECV_TIMEOUT 20000 |
| 15 | 15 | ||
| 16 | static int verbose = 0; | 16 | static int verbose = 0; |
| 17 | 17 | ||
| @@ -75,7 +75,7 @@ int connect_unix_socket(const char *filename) | |||
| 75 | 75 | ||
| 76 | // check if socket file exists... | 76 | // check if socket file exists... |
| 77 | if (stat(filename, &fst) != 0) { | 77 | if (stat(filename, &fst) != 0) { |
| 78 | if (verbose >= 2) fprintf(stderr, "%s: stat '%s': %s\n", __func__, filename, strerror(errno)); | 78 | if (verbose >= 2) fprintf(stderr, "%s: stat '%s': %s\n", __func__, filename, strerror(errno)); |
| 79 | return -1; | 79 | return -1; |
| 80 | } | 80 | } |
| 81 | 81 | ||
