diff options
| -rw-r--r-- | libusbmuxd/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | libusbmuxd/libusbmuxd.c | 24 | ||||
| -rw-r--r-- | tools/iproxy.c | 32 |
3 files changed, 57 insertions, 2 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}) | |||
| 33 | if(APPLE) | 33 | if(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}") |
| 35 | endif() | 35 | endif() |
| 36 | if(WIN32) | ||
| 37 | set_target_properties(libusbmuxd PROPERTIES PREFIX "lib" IMPORT_PREFIX "lib") | ||
| 38 | endif() | ||
| 36 | 39 | ||
| 37 | install(TARGETS libusbmuxd | 40 | install(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 | ||
| 66 | static struct collection devices; | 68 | static struct collection devices; |
| 67 | static usbmuxd_event_cb_t event_cb = NULL; | 69 | static usbmuxd_event_cb_t event_cb = NULL; |
| 70 | #ifdef WIN32 | ||
| 71 | HANDLE devmon = NULL; | ||
| 72 | #else | ||
| 68 | pthread_t devmon; | 73 | pthread_t devmon; |
| 74 | #endif | ||
| 69 | static int listenfd = -1; | 75 | static int listenfd = -1; |
| 70 | 76 | ||
| 71 | static int use_tag = 0; | 77 | static 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 | } |
diff --git a/tools/iproxy.c b/tools/iproxy.c index 4469c48..0bc38fb 100644 --- a/tools/iproxy.c +++ b/tools/iproxy.c | |||
| @@ -40,9 +40,9 @@ typedef unsigned int socklen_t; | |||
| 40 | #include <sys/socket.h> | 40 | #include <sys/socket.h> |
| 41 | #include <sys/un.h> | 41 | #include <sys/un.h> |
| 42 | #include <arpa/inet.h> | 42 | #include <arpa/inet.h> |
| 43 | #endif | ||
| 44 | #include <pthread.h> | 43 | #include <pthread.h> |
| 45 | #include <netinet/in.h> | 44 | #include <netinet/in.h> |
| 45 | #endif | ||
| 46 | #include "sock_stuff.h" | 46 | #include "sock_stuff.h" |
| 47 | #include "usbmuxd.h" | 47 | #include "usbmuxd.h" |
| 48 | 48 | ||
| @@ -105,12 +105,20 @@ void *run_ctos_loop(void *arg) | |||
| 105 | int recv_len; | 105 | int recv_len; |
| 106 | int sent; | 106 | int sent; |
| 107 | char buffer[131072]; | 107 | char buffer[131072]; |
| 108 | #ifdef WIN32 | ||
| 109 | HANDLE stoc = NULL; | ||
| 110 | #else | ||
| 108 | pthread_t stoc; | 111 | pthread_t stoc; |
| 112 | #endif | ||
| 109 | 113 | ||
| 110 | printf("%s: fd = %d\n", __func__, cdata->fd); | 114 | printf("%s: fd = %d\n", __func__, cdata->fd); |
| 111 | 115 | ||
| 112 | cdata->stop_stoc = 0; | 116 | cdata->stop_stoc = 0; |
| 117 | #ifdef WIN32 | ||
| 118 | stoc = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)run_stoc_loop, cdata, 0, NULL); | ||
| 119 | #else | ||
| 113 | pthread_create(&stoc, NULL, run_stoc_loop, cdata); | 120 | pthread_create(&stoc, NULL, run_stoc_loop, cdata); |
| 121 | #endif | ||
| 114 | 122 | ||
| 115 | while (!cdata->stop_ctos && cdata->fd>0 && cdata->sfd>0) { | 123 | while (!cdata->stop_ctos && cdata->fd>0 && cdata->sfd>0) { |
| 116 | recv_len = recv_buf_timeout(cdata->fd, buffer, sizeof(buffer), 0, 5000); | 124 | recv_len = recv_buf_timeout(cdata->fd, buffer, sizeof(buffer), 0, 5000); |
| @@ -143,7 +151,11 @@ void *run_ctos_loop(void *arg) | |||
| 143 | cdata->fd = -1; | 151 | cdata->fd = -1; |
| 144 | cdata->stop_stoc = 1; | 152 | cdata->stop_stoc = 1; |
| 145 | 153 | ||
| 154 | #ifdef WIN32 | ||
| 155 | WaitForSingleObject(stoc, INFINITE); | ||
| 156 | #else | ||
| 146 | pthread_join(stoc, NULL); | 157 | pthread_join(stoc, NULL); |
| 158 | #endif | ||
| 147 | 159 | ||
| 148 | return NULL; | 160 | return NULL; |
| 149 | } | 161 | } |
| @@ -152,7 +164,11 @@ void *acceptor_thread(void *arg) | |||
| 152 | { | 164 | { |
| 153 | struct client_data *cdata; | 165 | struct client_data *cdata; |
| 154 | usbmuxd_device_info_t *dev_list = NULL; | 166 | usbmuxd_device_info_t *dev_list = NULL; |
| 167 | #ifdef WIN32 | ||
| 168 | HANDLE ctos = NULL; | ||
| 169 | #else | ||
| 155 | pthread_t ctos; | 170 | pthread_t ctos; |
| 171 | #endif | ||
| 156 | int count; | 172 | int count; |
| 157 | 173 | ||
| 158 | if (!arg) { | 174 | if (!arg) { |
| @@ -184,8 +200,13 @@ void *acceptor_thread(void *arg) | |||
| 184 | fprintf(stderr, "Error connecting to device!\n"); | 200 | fprintf(stderr, "Error connecting to device!\n"); |
| 185 | } else { | 201 | } else { |
| 186 | cdata->stop_ctos = 0; | 202 | cdata->stop_ctos = 0; |
| 203 | #ifdef WIN32 | ||
| 204 | ctos = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)run_ctos_loop, cdata, 0, NULL); | ||
| 205 | WaitForSingleObject(ctos, INFINITE); | ||
| 206 | #else | ||
| 187 | pthread_create(&ctos, NULL, run_ctos_loop, cdata); | 207 | pthread_create(&ctos, NULL, run_ctos_loop, cdata); |
| 188 | pthread_join(ctos, NULL); | 208 | pthread_join(ctos, NULL); |
| 209 | #endif | ||
| 189 | } | 210 | } |
| 190 | 211 | ||
| 191 | if (cdata->fd > 0) { | 212 | if (cdata->fd > 0) { |
| @@ -226,7 +247,11 @@ int main(int argc, char **argv) | |||
| 226 | fprintf(stderr, "Error creating socket: %s\n", strerror(errno)); | 247 | fprintf(stderr, "Error creating socket: %s\n", strerror(errno)); |
| 227 | return -errno; | 248 | return -errno; |
| 228 | } else { | 249 | } else { |
| 250 | #ifdef WIN32 | ||
| 251 | HANDLE acceptor = NULL; | ||
| 252 | #else | ||
| 229 | pthread_t acceptor; | 253 | pthread_t acceptor; |
| 254 | #endif | ||
| 230 | struct sockaddr_in c_addr; | 255 | struct sockaddr_in c_addr; |
| 231 | socklen_t len = sizeof(struct sockaddr_in); | 256 | socklen_t len = sizeof(struct sockaddr_in); |
| 232 | struct client_data cdata; | 257 | struct client_data cdata; |
| @@ -237,8 +262,13 @@ int main(int argc, char **argv) | |||
| 237 | if (c_sock) { | 262 | if (c_sock) { |
| 238 | printf("accepted connection, fd = %d\n", c_sock); | 263 | printf("accepted connection, fd = %d\n", c_sock); |
| 239 | cdata.fd = c_sock; | 264 | cdata.fd = c_sock; |
| 265 | #ifdef WIN32 | ||
| 266 | acceptor = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)acceptor_thread, &cdata, 0, NULL); | ||
| 267 | WaitForSingleObject(acceptor, INFINITE); | ||
| 268 | #else | ||
| 240 | pthread_create(&acceptor, NULL, acceptor_thread, &cdata); | 269 | pthread_create(&acceptor, NULL, acceptor_thread, &cdata); |
| 241 | pthread_join(acceptor, NULL); | 270 | pthread_join(acceptor, NULL); |
| 271 | #endif | ||
| 242 | } else { | 272 | } else { |
| 243 | break; | 273 | break; |
| 244 | } | 274 | } |
