summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-06-20 04:29:23 +0200
committerGravatar Nikias Bassen2009-06-20 04:29:23 +0200
commit94d700159d010176a57640d6f59476aaf43875fc (patch)
treee215eab15d5857b7eb7ef82deebee73cc3cbc1eb /src/main.c
parentbb33ccdf06f261dca033d70772bc256c890c76f7 (diff)
downloadusbmuxd-94d700159d010176a57640d6f59476aaf43875fc.tar.gz
usbmuxd-94d700159d010176a57640d6f59476aaf43875fc.tar.bz2
hopefully fixed race condition on connection setup
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 1a62f17..8e27d8f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -719,6 +719,7 @@ static void *usbmuxd_client_init_thread(void *arg)
logmsg(LOG_NOTICE,
"%s[%x]: No attached iPhone/iPod devices found.",
__func__, THREAD);
+ usbmuxd_send_result(cdata->socket, s_req->header.tag, -ENODEV);
goto leave;
}
@@ -846,6 +847,27 @@ static void *usbmuxd_client_init_thread(void *arg)
}
pthread_mutex_unlock(&cur_dev->mutex);
+ // wait for the initial handshake (SYN->SYN+ACK->ACKto complete
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 100000000;
+
+ i = 0;
+ printf("waiting for handshake to complete...\n");
+ while (i < 10000) {
+ if (usbmux_is_connected(cdata->muxclient)) {
+ printf("handshake done\n");
+ break;
+ }
+ nanosleep(&ts, NULL);
+ i+=100;
+ }
+ if (!usbmux_is_connected(cdata->muxclient)) {
+ printf("handshake failed\n");
+ usbmuxd_send_result(cdata->socket, c_req->header.tag, -ENOTCONN);
+ goto leave;
+ }
+
// start connection handler thread
cdata->handler_dead = 0;
cdata->tag = c_req->header.tag;