From 68bf4383aeb993fc20a7214fdd0582348ebd2dbd Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Fri, 13 Mar 2015 16:29:35 +0100 Subject: [PATCH] MSW: fixed some other close->closesocket occurencies --- src/control_socket.cpp | 17 +++++++++++------ src/switcher_control_keyboard.c | 13 +++++++++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/control_socket.cpp b/src/control_socket.cpp index d0ac4904d..2b87d9a51 100644 --- a/src/control_socket.cpp +++ b/src/control_socket.cpp @@ -71,6 +71,11 @@ typedef const char *sso_val_type; typedef void *sso_val_type; #endif /* WIN32 */ +#ifdef WIN32 +#define CLOSESOCKET closesocket +#else +#define CLOSESOCKET close +#endif using namespace std; @@ -264,7 +269,7 @@ void control_start(struct control_state *s) } s->internal_fd[0] = accept(sock, NULL, NULL); - close(sock); + CLOSESOCKET(sock); s->started = true; } @@ -588,7 +593,7 @@ static void * control_thread(void *args) } if(ret == 0) { struct client *next; - close(cur->fd); + CLOSESOCKET(cur->fd); if(cur->prev) { cur->prev->next = cur->next; } else { @@ -673,12 +678,12 @@ static void * control_thread(void *args) struct client *cur = clients; while(cur) { struct client *tmp = cur; - close(cur->fd); + CLOSESOCKET(cur->fd); cur = cur->next; free(tmp); } - close(s->internal_fd[1]); + CLOSESOCKET(s->internal_fd[1]); return NULL; } @@ -695,7 +700,7 @@ void control_done(struct control_state *s) int ret = write_all(s->internal_fd[0], "quit\r\n", 6); if (ret > 0) { pthread_join(s->thread_id, NULL); - close(s->internal_fd[0]); + CLOSESOCKET(s->internal_fd[0]); } else { fprintf(stderr, "Cannot exit control thread!\n"); } @@ -703,7 +708,7 @@ void control_done(struct control_state *s) if(s->connection_type == SERVER) { // for client, the socket has already been closed // by the time of control_thread exit - close(s->socket_fd); + CLOSESOCKET(s->socket_fd); } pthread_mutex_destroy(&s->stats_lock); diff --git a/src/switcher_control_keyboard.c b/src/switcher_control_keyboard.c index ec0cafe70..0398532d2 100644 --- a/src/switcher_control_keyboard.c +++ b/src/switcher_control_keyboard.c @@ -13,6 +13,13 @@ #include #include "debug.h" +#ifdef WIN32 +#define CLOSESOCKET closesocket +#else +#define CLOSESOCKET close +#endif + + void usage(const char *progname); int main(int argc, char *argv[]); void sig_handler(int signal); @@ -25,7 +32,7 @@ int fd = -1;// = socket(AF_INET6, SOCK_STREAM, 0); void sig_handler(int signal) { UNUSED(signal); - close(fd); + CLOSESOCKET(fd); endwin(); exit(EXIT_SUCCESS); } @@ -165,7 +172,9 @@ finish: #endif pthread_join(reading_thread_id, NULL); - close(fd); +#ifndef WIN32 + CLOSESOCKET(fd); +#endif endwin(); #ifdef WIN32