summaryrefslogtreecommitdiffstats
path: root/libusbmuxd/libusbmuxd.c
diff options
context:
space:
mode:
Diffstat (limited to 'libusbmuxd/libusbmuxd.c')
-rw-r--r--libusbmuxd/libusbmuxd.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/libusbmuxd/libusbmuxd.c b/libusbmuxd/libusbmuxd.c
index 304e8da..e06ee61 100644
--- a/libusbmuxd/libusbmuxd.c
+++ b/libusbmuxd/libusbmuxd.c
@@ -30,9 +30,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30#include <windows.h> 30#include <windows.h>
31#include <winsock2.h> 31#include <winsock2.h>
32#define sleep(x) Sleep(x*1000) 32#define sleep(x) Sleep(x*1000)
33#define EPROTO 71
34#define EBADMSG 77
33#else 35#else
34#include <sys/socket.h> 36#include <sys/socket.h>
35#include <arpa/inet.h> 37#include <arpa/inet.h>
38#include <pthread.h>
36#endif 39#endif
37 40
38#ifdef HAVE_INOTIFY 41#ifdef HAVE_INOTIFY
@@ -45,7 +48,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
45 48
46#include <unistd.h> 49#include <unistd.h>
47#include <signal.h> 50#include <signal.h>
48#include <pthread.h>
49 51
50#ifdef HAVE_PLIST 52#ifdef HAVE_PLIST
51#include <plist/plist.h> 53#include <plist/plist.h>
@@ -65,7 +67,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
65 67
66static struct collection devices; 68static struct collection devices;
67static usbmuxd_event_cb_t event_cb = NULL; 69static usbmuxd_event_cb_t event_cb = NULL;
70#ifdef WIN32
71HANDLE devmon = NULL;
72#else
68pthread_t devmon; 73pthread_t devmon;
74#endif
69static int listenfd = -1; 75static int listenfd = -1;
70 76
71static int use_tag = 0; 77static int use_tag = 0;
@@ -605,7 +611,15 @@ int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data)
605 } 611 }
606 event_cb = callback; 612 event_cb = callback;
607 613
614#ifdef WIN32
615 res = 0;
616 devmon = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)device_monitor, user_data, 0, NULL);
617 if (devmon == NULL) {
618 res = GetLastError();
619 }
620#else
608 res = pthread_create(&devmon, NULL, device_monitor, user_data); 621 res = pthread_create(&devmon, NULL, device_monitor, user_data);
622#endif
609 if (res != 0) { 623 if (res != 0) {
610 fprintf(stderr, "%s: ERROR: Could not start device watcher thread!\n", __func__); 624 fprintf(stderr, "%s: ERROR: Could not start device watcher thread!\n", __func__);
611 return res; 625 return res;
@@ -617,12 +631,20 @@ int usbmuxd_unsubscribe()
617{ 631{
618 event_cb = NULL; 632 event_cb = NULL;
619 633
634#ifdef WIN32
635 if (devmon != NULL) {
636 close_socket(listenfd);
637 listenfd = -1;
638 WaitForSingleObject(devmon, INFINITE);
639 }
640#else
620 if (pthread_kill(devmon, 0) == 0) { 641 if (pthread_kill(devmon, 0) == 0) {
621 close_socket(listenfd); 642 close_socket(listenfd);
622 listenfd = -1; 643 listenfd = -1;
623 pthread_kill(devmon, SIGINT); 644 pthread_kill(devmon, SIGINT);
624 pthread_join(devmon, NULL); 645 pthread_join(devmon, NULL);
625 } 646 }
647#endif
626 648
627 return 0; 649 return 0;
628} 650}