summaryrefslogtreecommitdiffstats
path: root/libusbmuxd
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2011-01-08 16:15:40 +0100
committerGravatar Nikias Bassen2011-01-08 16:15:40 +0100
commit32e27781dc6e4d2ef3508a0708284f22ee16ea1c (patch)
tree507a325cc4348799ae141708454332d2d0e0d9bc /libusbmuxd
parent0ca8f1c05bea2c1f4d53aa165079588ea6519847 (diff)
downloadusbmuxd-32e27781dc6e4d2ef3508a0708284f22ee16ea1c.tar.gz
usbmuxd-32e27781dc6e4d2ef3508a0708284f22ee16ea1c.tar.bz2
libusbmuxd/iproxy: use windows threads instead of pthread for win32 build
Diffstat (limited to 'libusbmuxd')
-rw-r--r--libusbmuxd/CMakeLists.txt3
-rw-r--r--libusbmuxd/libusbmuxd.c24
2 files changed, 26 insertions, 1 deletions
diff --git a/libusbmuxd/CMakeLists.txt b/libusbmuxd/CMakeLists.txt
index a3d5fbe..737eb02 100644
--- a/libusbmuxd/CMakeLists.txt
+++ b/libusbmuxd/CMakeLists.txt
@@ -33,6 +33,9 @@ set_target_properties(libusbmuxd PROPERTIES SOVERSION ${LIBUSBMUXD_SOVERSION})
33if(APPLE) 33if(APPLE)
34 set_target_properties(libusbmuxd PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") 34 set_target_properties(libusbmuxd PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
35endif() 35endif()
36if(WIN32)
37 set_target_properties(libusbmuxd PROPERTIES PREFIX "lib" IMPORT_PREFIX "lib")
38endif()
36 39
37install(TARGETS libusbmuxd 40install(TARGETS libusbmuxd
38 RUNTIME DESTINATION bin 41 RUNTIME DESTINATION bin
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}