summaryrefslogtreecommitdiffstats
path: root/libusbmuxd
diff options
context:
space:
mode:
authorGravatar David Sansome2010-09-25 16:52:10 +0200
committerGravatar Hector Martin2010-09-25 16:52:10 +0200
commit8e5f8a700569015bc36a84850c6d4b4bba5cd1ae (patch)
tree3ba5d02dc1df0bf7873d11d19f32376faf7fe234 /libusbmuxd
parent80e41939e3ae4d8c9e7184c31858b6689822f3d0 (diff)
downloadusbmuxd-8e5f8a700569015bc36a84850c6d4b4bba5cd1ae.tar.gz
usbmuxd-8e5f8a700569015bc36a84850c6d4b4bba5cd1ae.tar.bz2
Use Winsock's closesocket() function instead of close() on Windows.
Diffstat (limited to 'libusbmuxd')
-rw-r--r--libusbmuxd/libusbmuxd.c18
-rw-r--r--libusbmuxd/sock_stuff.c24
-rw-r--r--libusbmuxd/sock_stuff.h2
3 files changed, 27 insertions, 17 deletions
diff --git a/libusbmuxd/libusbmuxd.c b/libusbmuxd/libusbmuxd.c
index bb30c04..5eaf8e6 100644
--- a/libusbmuxd/libusbmuxd.c
+++ b/libusbmuxd/libusbmuxd.c
@@ -277,7 +277,7 @@ static int send_packet(int sfd, uint32_t message, uint32_t tag, void *payload, u
277 } 277 }
278 if (sent != (int)header.length) { 278 if (sent != (int)header.length) {
279 fprintf(stderr, "%s: ERROR: could not send whole packet\n", __func__); 279 fprintf(stderr, "%s: ERROR: could not send whole packet\n", __func__);
280 close(sfd); 280 close_socket(sfd);
281 return -1; 281 return -1;
282 } 282 }
283 return sent; 283 return sent;
@@ -405,11 +405,11 @@ retry:
405 use_tag++; 405 use_tag++;
406 if (send_listen_packet(sfd, use_tag) <= 0) { 406 if (send_listen_packet(sfd, use_tag) <= 0) {
407 fprintf(stderr, "%s: ERROR: could not send listen packet\n", __func__); 407 fprintf(stderr, "%s: ERROR: could not send listen packet\n", __func__);
408 close(sfd); 408 close_socket(sfd);
409 return -1; 409 return -1;
410 } 410 }
411 if (usbmuxd_get_result(sfd, use_tag, &res) && (res != 0)) { 411 if (usbmuxd_get_result(sfd, use_tag, &res) && (res != 0)) {
412 close(sfd); 412 close_socket(sfd);
413#ifdef HAVE_PLIST 413#ifdef HAVE_PLIST
414 if ((res == RESULT_BADVERSION) && (proto_version != 1)) { 414 if ((res == RESULT_BADVERSION) && (proto_version != 1)) {
415 proto_version = 1; 415 proto_version = 1;
@@ -538,7 +538,7 @@ int usbmuxd_unsubscribe()
538 event_cb = NULL; 538 event_cb = NULL;
539 539
540 if (pthread_kill(devmon, 0) == 0) { 540 if (pthread_kill(devmon, 0) == 0) {
541 close(listenfd); 541 close_socket(listenfd);
542 listenfd = -1; 542 listenfd = -1;
543 pthread_kill(devmon, SIGINT); 543 pthread_kill(devmon, SIGINT);
544 pthread_join(devmon, NULL); 544 pthread_join(devmon, NULL);
@@ -574,7 +574,7 @@ retry:
574 if (usbmuxd_get_result(sfd, use_tag, &res) && (res == 0)) { 574 if (usbmuxd_get_result(sfd, use_tag, &res) && (res == 0)) {
575 listen_success = 1; 575 listen_success = 1;
576 } else { 576 } else {
577 close(sfd); 577 close_socket(sfd);
578#ifdef HAVE_PLIST 578#ifdef HAVE_PLIST
579 if ((res == RESULT_BADVERSION) && (proto_version != 1)) { 579 if ((res == RESULT_BADVERSION) && (proto_version != 1)) {
580 proto_version = 1; 580 proto_version = 1;
@@ -633,7 +633,7 @@ retry:
633 } 633 }
634 634
635 // explicitly close connection 635 // explicitly close connection
636 close(sfd); 636 close_socket(sfd);
637 637
638 // terminating zero record 638 // terminating zero record
639 newlist = (usbmuxd_device_info_t*) realloc(*device_list, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1)); 639 newlist = (usbmuxd_device_info_t*) realloc(*device_list, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1));
@@ -716,7 +716,7 @@ retry:
716#ifdef HAVE_PLIST 716#ifdef HAVE_PLIST
717 if ((res == RESULT_BADVERSION) && (proto_version == 0)) { 717 if ((res == RESULT_BADVERSION) && (proto_version == 0)) {
718 proto_version = 1; 718 proto_version = 1;
719 close(sfd); 719 close_socket(sfd);
720 goto retry; 720 goto retry;
721 } 721 }
722#endif 722#endif
@@ -730,14 +730,14 @@ retry:
730 return sfd; 730 return sfd;
731 } 731 }
732 732
733 close(sfd); 733 close_socket(sfd);
734 734
735 return -1; 735 return -1;
736} 736}
737 737
738int usbmuxd_disconnect(int sfd) 738int usbmuxd_disconnect(int sfd)
739{ 739{
740 return close(sfd); 740 return close_socket(sfd);
741} 741}
742 742
743int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes) 743int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes)
diff --git a/libusbmuxd/sock_stuff.c b/libusbmuxd/sock_stuff.c
index 302b53a..edc738e 100644
--- a/libusbmuxd/sock_stuff.c
+++ b/libusbmuxd/sock_stuff.c
@@ -85,13 +85,13 @@ int create_unix_socket(const char *filename)
85 85
86 if (bind(sock, (struct sockaddr *) &name, size) < 0) { 86 if (bind(sock, (struct sockaddr *) &name, size) < 0) {
87 perror("bind"); 87 perror("bind");
88 close(sock); 88 close_socket(sock);
89 return -1; 89 return -1;
90 } 90 }
91 91
92 if (listen(sock, 10) < 0) { 92 if (listen(sock, 10) < 0) {
93 perror("listen"); 93 perror("listen");
94 close(sock); 94 close_socket(sock);
95 return -1; 95 return -1;
96 } 96 }
97 97
@@ -134,7 +134,7 @@ int connect_unix_socket(const char *filename)
134 + strlen(name.sun_path) + 1); 134 + strlen(name.sun_path) + 1);
135 135
136 if (connect(sfd, (struct sockaddr *) &name, size) < 0) { 136 if (connect(sfd, (struct sockaddr *) &name, size) < 0) {
137 close(sfd); 137 close_socket(sfd);
138 if (verbose >= 2) 138 if (verbose >= 2)
139 fprintf(stderr, "%s: connect: %s\n", __func__, 139 fprintf(stderr, "%s: connect: %s\n", __func__,
140 strerror(errno)); 140 strerror(errno));
@@ -168,7 +168,7 @@ int create_socket(uint16_t port)
168 168
169 if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(int)) == -1) { 169 if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(int)) == -1) {
170 perror("setsockopt()"); 170 perror("setsockopt()");
171 close(sfd); 171 close_socket(sfd);
172 return -1; 172 return -1;
173 } 173 }
174 174
@@ -179,13 +179,13 @@ int create_socket(uint16_t port)
179 179
180 if (0 > bind(sfd, (struct sockaddr *) &saddr, sizeof(saddr))) { 180 if (0 > bind(sfd, (struct sockaddr *) &saddr, sizeof(saddr))) {
181 perror("bind()"); 181 perror("bind()");
182 close(sfd); 182 close_socket(sfd);
183 return -1; 183 return -1;
184 } 184 }
185 185
186 if (listen(sfd, 1) == -1) { 186 if (listen(sfd, 1) == -1) {
187 perror("listen()"); 187 perror("listen()");
188 close(sfd); 188 close_socket(sfd);
189 return -1; 189 return -1;
190 } 190 }
191 191
@@ -235,7 +235,7 @@ int connect_socket(const char *addr, uint16_t port)
235 235
236 if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(int)) == -1) { 236 if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(int)) == -1) {
237 perror("setsockopt()"); 237 perror("setsockopt()");
238 close(sfd); 238 close_socket(sfd);
239 return -1; 239 return -1;
240 } 240 }
241 241
@@ -246,7 +246,7 @@ int connect_socket(const char *addr, uint16_t port)
246 246
247 if (connect(sfd, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) { 247 if (connect(sfd, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) {
248 perror("connect"); 248 perror("connect");
249 close(sfd); 249 close_socket(sfd);
250 return -2; 250 return -2;
251 } 251 }
252 252
@@ -321,6 +321,14 @@ int check_fd(int fd, fd_mode fdm, unsigned int timeout)
321 return sret; 321 return sret;
322} 322}
323 323
324int close_socket(int fd) {
325#ifdef WIN32
326 return closesocket(fd);
327#else
328 return close(fd);
329#endif
330}
331
324int recv_buf(int fd, void *data, size_t length) 332int recv_buf(int fd, void *data, size_t length)
325{ 333{
326 return recv_buf_timeout(fd, data, length, 0, RECV_TIMEOUT); 334 return recv_buf_timeout(fd, data, length, 0, RECV_TIMEOUT);
diff --git a/libusbmuxd/sock_stuff.h b/libusbmuxd/sock_stuff.h
index db90385..eb9622c 100644
--- a/libusbmuxd/sock_stuff.h
+++ b/libusbmuxd/sock_stuff.h
@@ -43,6 +43,8 @@ int connect_socket(const char *addr, uint16_t port);
43#endif 43#endif
44int check_fd(int fd, fd_mode fdm, unsigned int timeout); 44int check_fd(int fd, fd_mode fdm, unsigned int timeout);
45 45
46int close_socket(int fd);
47
46int recv_buf(int fd, void *data, size_t size); 48int recv_buf(int fd, void *data, size_t size);
47int peek_buf(int fd, void *data, size_t size); 49int peek_buf(int fd, void *data, size_t size);
48int recv_buf_timeout(int fd, void *data, size_t size, int flags, 50int recv_buf_timeout(int fd, void *data, size_t size, int flags,