diff options
| author | 2011-01-08 16:15:40 +0100 | |
|---|---|---|
| committer | 2011-01-08 16:15:40 +0100 | |
| commit | 32e27781dc6e4d2ef3508a0708284f22ee16ea1c (patch) | |
| tree | 507a325cc4348799ae141708454332d2d0e0d9bc /tools/iproxy.c | |
| parent | 0ca8f1c05bea2c1f4d53aa165079588ea6519847 (diff) | |
| download | usbmuxd-32e27781dc6e4d2ef3508a0708284f22ee16ea1c.tar.gz usbmuxd-32e27781dc6e4d2ef3508a0708284f22ee16ea1c.tar.bz2 | |
libusbmuxd/iproxy: use windows threads instead of pthread for win32 build
Diffstat (limited to 'tools/iproxy.c')
| -rw-r--r-- | tools/iproxy.c | 32 |
1 files changed, 31 insertions, 1 deletions
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 | } |
