diff options
| author | 2009-06-20 04:29:23 +0200 | |
|---|---|---|
| committer | 2009-06-20 04:29:23 +0200 | |
| commit | 94d700159d010176a57640d6f59476aaf43875fc (patch) | |
| tree | e215eab15d5857b7eb7ef82deebee73cc3cbc1eb /src | |
| parent | bb33ccdf06f261dca033d70772bc256c890c76f7 (diff) | |
| download | usbmuxd-94d700159d010176a57640d6f59476aaf43875fc.tar.gz usbmuxd-94d700159d010176a57640d6f59476aaf43875fc.tar.bz2 | |
hopefully fixed race condition on connection setup
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 22 | ||||
| -rw-r--r-- | src/usbmux.c | 13 | ||||
| -rw-r--r-- | src/usbmux.h | 2 |
3 files changed, 37 insertions, 0 deletions
| @@ -719,6 +719,7 @@ static void *usbmuxd_client_init_thread(void *arg) | |||
| 719 | logmsg(LOG_NOTICE, | 719 | logmsg(LOG_NOTICE, |
| 720 | "%s[%x]: No attached iPhone/iPod devices found.", | 720 | "%s[%x]: No attached iPhone/iPod devices found.", |
| 721 | __func__, THREAD); | 721 | __func__, THREAD); |
| 722 | usbmuxd_send_result(cdata->socket, s_req->header.tag, -ENODEV); | ||
| 722 | goto leave; | 723 | goto leave; |
| 723 | } | 724 | } |
| 724 | 725 | ||
| @@ -846,6 +847,27 @@ static void *usbmuxd_client_init_thread(void *arg) | |||
| 846 | } | 847 | } |
| 847 | pthread_mutex_unlock(&cur_dev->mutex); | 848 | pthread_mutex_unlock(&cur_dev->mutex); |
| 848 | 849 | ||
| 850 | // wait for the initial handshake (SYN->SYN+ACK->ACKto complete | ||
| 851 | struct timespec ts; | ||
| 852 | ts.tv_sec = 0; | ||
| 853 | ts.tv_nsec = 100000000; | ||
| 854 | |||
| 855 | i = 0; | ||
| 856 | printf("waiting for handshake to complete...\n"); | ||
| 857 | while (i < 10000) { | ||
| 858 | if (usbmux_is_connected(cdata->muxclient)) { | ||
| 859 | printf("handshake done\n"); | ||
| 860 | break; | ||
| 861 | } | ||
| 862 | nanosleep(&ts, NULL); | ||
| 863 | i+=100; | ||
| 864 | } | ||
| 865 | if (!usbmux_is_connected(cdata->muxclient)) { | ||
| 866 | printf("handshake failed\n"); | ||
| 867 | usbmuxd_send_result(cdata->socket, c_req->header.tag, -ENOTCONN); | ||
| 868 | goto leave; | ||
| 869 | } | ||
| 870 | |||
| 849 | // start connection handler thread | 871 | // start connection handler thread |
| 850 | cdata->handler_dead = 0; | 872 | cdata->handler_dead = 0; |
| 851 | cdata->tag = c_req->header.tag; | 873 | cdata->tag = c_req->header.tag; |
diff --git a/src/usbmux.c b/src/usbmux.c index 87cdede..927928e 100644 --- a/src/usbmux.c +++ b/src/usbmux.c | |||
| @@ -100,6 +100,8 @@ struct usbmux_client_int { | |||
| 100 | int error; | 100 | int error; |
| 101 | 101 | ||
| 102 | int cleanup; | 102 | int cleanup; |
| 103 | |||
| 104 | int connected; | ||
| 103 | }; | 105 | }; |
| 104 | 106 | ||
| 105 | 107 | ||
| @@ -734,6 +736,7 @@ int usbmux_new_client(usbmux_device_t device, uint16_t src_port, | |||
| 734 | add_connection(new_connection); | 736 | add_connection(new_connection); |
| 735 | new_connection->error = 0; | 737 | new_connection->error = 0; |
| 736 | new_connection->cleanup = 0; | 738 | new_connection->cleanup = 0; |
| 739 | new_connection->connected = 0; | ||
| 737 | hton_header(new_connection->header); | 740 | hton_header(new_connection->header); |
| 738 | log_debug_msg("%s: send_to_device (%d --> %d)\n", __func__, | 741 | log_debug_msg("%s: send_to_device (%d --> %d)\n", __func__, |
| 739 | ntohs(new_connection->header->sport), | 742 | ntohs(new_connection->header->sport), |
| @@ -931,6 +934,8 @@ uint32_t append_receive_buffer(usbmux_client_t client, char *packet) | |||
| 931 | sizeof(usbmux_tcp_header)) <= 0) { | 934 | sizeof(usbmux_tcp_header)) <= 0) { |
| 932 | log_debug_msg("%s: error when pushing to usb...\n", | 935 | log_debug_msg("%s: error when pushing to usb...\n", |
| 933 | __func__); | 936 | __func__); |
| 937 | } else { | ||
| 938 | client->connected = 1; | ||
| 934 | } | 939 | } |
| 935 | // need to revert some of the fields back to host notation. | 940 | // need to revert some of the fields back to host notation. |
| 936 | ntoh_header(client->header); | 941 | ntoh_header(client->header); |
| @@ -1253,3 +1258,11 @@ int usbmux_recv_timeout(usbmux_client_t client, char *data, | |||
| 1253 | 1258 | ||
| 1254 | return 0; | 1259 | return 0; |
| 1255 | } | 1260 | } |
| 1261 | |||
| 1262 | int usbmux_is_connected(usbmux_client_t client) | ||
| 1263 | { | ||
| 1264 | if (!client) { | ||
| 1265 | return 0; | ||
| 1266 | } | ||
| 1267 | return client->connected; | ||
| 1268 | } | ||
diff --git a/src/usbmux.h b/src/usbmux.h index 2bcdb15..155316a 100644 --- a/src/usbmux.h +++ b/src/usbmux.h | |||
| @@ -48,4 +48,6 @@ int usbmux_pullbulk(usbmux_device_t device); | |||
| 48 | 48 | ||
| 49 | int usbmux_get_error(usbmux_client_t client); | 49 | int usbmux_get_error(usbmux_client_t client); |
| 50 | 50 | ||
| 51 | int usbmux_is_connected(usbmux_client_t client); | ||
| 52 | |||
| 51 | #endif | 53 | #endif |
