summaryrefslogtreecommitdiffstats
path: root/libusbmuxd
diff options
context:
space:
mode:
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
}
if (sent != (int)header.length) {
fprintf(stderr, "%s: ERROR: could not send whole packet\n", __func__);
- close(sfd);
+ close_socket(sfd);
return -1;
}
return sent;
@@ -405,11 +405,11 @@ retry:
use_tag++;
if (send_listen_packet(sfd, use_tag) <= 0) {
fprintf(stderr, "%s: ERROR: could not send listen packet\n", __func__);
- close(sfd);
+ close_socket(sfd);
return -1;
}
if (usbmuxd_get_result(sfd, use_tag, &res) && (res != 0)) {
- close(sfd);
+ close_socket(sfd);
#ifdef HAVE_PLIST
if ((res == RESULT_BADVERSION) && (proto_version != 1)) {
proto_version = 1;
@@ -538,7 +538,7 @@ int usbmuxd_unsubscribe()
event_cb = NULL;
if (pthread_kill(devmon, 0) == 0) {
- close(listenfd);
+ close_socket(listenfd);
listenfd = -1;
pthread_kill(devmon, SIGINT);
pthread_join(devmon, NULL);
@@ -574,7 +574,7 @@ retry:
if (usbmuxd_get_result(sfd, use_tag, &res) && (res == 0)) {
listen_success = 1;
} else {
- close(sfd);
+ close_socket(sfd);
#ifdef HAVE_PLIST
if ((res == RESULT_BADVERSION) && (proto_version != 1)) {
proto_version = 1;
@@ -633,7 +633,7 @@ retry:
}
// explicitly close connection
- close(sfd);
+ close_socket(sfd);
// terminating zero record
newlist = (usbmuxd_device_info_t*) realloc(*device_list, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1));
@@ -716,7 +716,7 @@ retry:
#ifdef HAVE_PLIST
if ((res == RESULT_BADVERSION) && (proto_version == 0)) {
proto_version = 1;
- close(sfd);
+ close_socket(sfd);
goto retry;
}
#endif
@@ -730,14 +730,14 @@ retry:
return sfd;
}
- close(sfd);
+ close_socket(sfd);
return -1;
}
int usbmuxd_disconnect(int sfd)
{
- return close(sfd);
+ return close_socket(sfd);
}
int 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)
if (bind(sock, (struct sockaddr *) &name, size) < 0) {
perror("bind");
- close(sock);
+ close_socket(sock);
return -1;
}
if (listen(sock, 10) < 0) {
perror("listen");
- close(sock);
+ close_socket(sock);
return -1;
}
@@ -134,7 +134,7 @@ int connect_unix_socket(const char *filename)
+ strlen(name.sun_path) + 1);
if (connect(sfd, (struct sockaddr *) &name, size) < 0) {
- close(sfd);
+ close_socket(sfd);
if (verbose >= 2)
fprintf(stderr, "%s: connect: %s\n", __func__,
strerror(errno));
@@ -168,7 +168,7 @@ int create_socket(uint16_t port)
if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(int)) == -1) {
perror("setsockopt()");
- close(sfd);
+ close_socket(sfd);
return -1;
}
@@ -179,13 +179,13 @@ int create_socket(uint16_t port)
if (0 > bind(sfd, (struct sockaddr *) &saddr, sizeof(saddr))) {
perror("bind()");
- close(sfd);
+ close_socket(sfd);
return -1;
}
if (listen(sfd, 1) == -1) {
perror("listen()");
- close(sfd);
+ close_socket(sfd);
return -1;
}
@@ -235,7 +235,7 @@ int connect_socket(const char *addr, uint16_t port)
if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(int)) == -1) {
perror("setsockopt()");
- close(sfd);
+ close_socket(sfd);
return -1;
}
@@ -246,7 +246,7 @@ int connect_socket(const char *addr, uint16_t port)
if (connect(sfd, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) {
perror("connect");
- close(sfd);
+ close_socket(sfd);
return -2;
}
@@ -321,6 +321,14 @@ int check_fd(int fd, fd_mode fdm, unsigned int timeout)
return sret;
}
+int close_socket(int fd) {
+#ifdef WIN32
+ return closesocket(fd);
+#else
+ return close(fd);
+#endif
+}
+
int recv_buf(int fd, void *data, size_t length)
{
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);
#endif
int check_fd(int fd, fd_mode fdm, unsigned int timeout);
+int close_socket(int fd);
+
int recv_buf(int fd, void *data, size_t size);
int peek_buf(int fd, void *data, size_t size);
int recv_buf_timeout(int fd, void *data, size_t size, int flags,