diff options
author | Nikias Bassen | 2009-04-13 14:22:24 +0200 |
---|---|---|
committer | Nikias Bassen | 2009-04-13 14:22:24 +0200 |
commit | 9932dadfc7ddc65ccb3d2988df1a6dcc9cf536c5 (patch) | |
tree | 5e36527dc25154182889bd42bada7590f54a9c9d /main.c | |
parent | d6e0cb81973e99aa61c4b36e3e4a4dcd475c1e59 (diff) | |
download | usbmuxd-9932dadfc7ddc65ccb3d2988df1a6dcc9cf536c5.tar.gz usbmuxd-9932dadfc7ddc65ccb3d2988df1a6dcc9cf536c5.tar.bz2 |
This _should_ fix a race condition that happens when a client is about
to cleanup the stuff that is used by another client that is about to set
up a new connection. Increased timeout in sock_stuff from 10 to 20
seconds and decreased the pullbulk recv timeout from 5 to 3 seconds.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 11 |
1 files changed, 5 insertions, 6 deletions
@@ -605,11 +605,11 @@ connect: 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)); // find the device, and open usb connection + pthread_mutex_lock(&usbmux_mutex); phone = NULL; cur_dev = NULL; // first check if we already have an open connection if (devices) { - pthread_mutex_lock(&usbmux_mutex); for (i = 0; i < device_count; i++) { if (devices[i]) { if (devices[i]->device_id == c_req->device_id) { @@ -620,7 +620,6 @@ connect: } } } - pthread_mutex_unlock(&usbmux_mutex); } if (!phone) { // if not found, make a new connection @@ -629,6 +628,7 @@ connect: pthread_mutex_lock(&usb_mutex); if (iphone_get_specific_device(0, c_req->device_id, &phone) != IPHONE_E_SUCCESS) { pthread_mutex_unlock(&usb_mutex); + pthread_mutex_unlock(&usbmux_mutex); if (verbose >= 1) fprintf(stderr, "%s: device_id %d could not be opened\n", __func__, c_req->device_id); usbmuxd_send_result(cdata->socket, c_req->header.tag, ENODEV); goto leave; @@ -636,7 +636,6 @@ connect: pthread_mutex_unlock(&usb_mutex); // create device object - pthread_mutex_lock(&usbmux_mutex); if (verbose >= 3) fprintf(stderr, "%s: add to device list\n", __func__); cur_dev = (struct device_info*)malloc(sizeof(struct device_info)); memset(cur_dev, 0, sizeof(struct device_info)); @@ -655,10 +654,10 @@ connect: devices[device_count] = cur_dev; device_count++; } - pthread_mutex_unlock(&usbmux_mutex); } else { if (verbose >= 3) fprintf(stderr, "%s: reusing usb connection, device_id=%d\n", __func__, c_req->device_id); } + pthread_mutex_unlock(&usbmux_mutex); // setup connection to iPhone/iPod // pthread_mutex_lock(&usbmux_mutex); @@ -712,6 +711,7 @@ leave: // this has to be freed only if it's not in use anymore as it closes // the USB connection + pthread_mutex_lock(&usbmux_mutex); if (cur_dev) { pthread_mutex_lock(&cur_dev->mutex); if (cur_dev->use_count > 1) { @@ -733,7 +733,6 @@ leave: pthread_mutex_destroy(&cur_dev->mutex); free(cur_dev); cur_dev = NULL; - pthread_mutex_lock(&usbmux_mutex); if (device_count > 1) { struct device_info **newlist; int j; @@ -752,9 +751,9 @@ leave: devices = NULL; device_count = 0; } - pthread_mutex_unlock(&usbmux_mutex); } } + pthread_mutex_unlock(&usbmux_mutex); cdata->dead = 1; close(cdata->socket); |