diff --git a/src/control_socket.cpp b/src/control_socket.cpp index 209b3a16c..bb26cba65 100644 --- a/src/control_socket.cpp +++ b/src/control_socket.cpp @@ -63,6 +63,7 @@ #include "debug.h" #include "messaging.h" #include "module.h" +#include "rtp/net_udp.h" // socket_error #include "tv.h" #define DEFAULT_CONTROL_PORT 5054 @@ -564,7 +565,7 @@ static void * control_thread(void *args) clients = add_client(clients, s->socket_fd); } struct sockaddr_storage client_addr; - socklen_t len; + socklen_t len = sizeof client_addr; errno = 0; @@ -605,10 +606,16 @@ static void * control_thread(void *args) timeout_ptr = &timeout; } - if(select(max_fd, &fds, NULL, NULL, timeout_ptr) >= 1) { + int rc; + + if ((rc = select(max_fd, &fds, NULL, NULL, timeout_ptr)) >= 1) { if(s->connection_type == SERVER && FD_ISSET(s->socket_fd, &fds)) { int fd = accept(s->socket_fd, (struct sockaddr *) &client_addr, &len); - clients = add_client(clients, fd); + if (fd == INVALID_SOCKET) { + socket_error("[control socket] accept"); + } else { + clients = add_client(clients, fd); + } } struct client *cur = clients; @@ -640,6 +647,8 @@ static void * control_thread(void *args) } cur = cur->next; } + } else if (rc < 0) { + socket_error("[control socket] select"); } cur = clients; diff --git a/src/rtp/net_udp.cpp b/src/rtp/net_udp.cpp index 5facf11ad..8e2d30ef6 100644 --- a/src/rtp/net_udp.cpp +++ b/src/rtp/net_udp.cpp @@ -178,7 +178,7 @@ static void udp_clean_async_state(socket_udp *s); /* Support functions... */ /*****************************************************************************/ -static void socket_error(const char *msg, ...) +void socket_error(const char *msg, ...) { char buffer[255]; uint32_t blen = sizeof(buffer) / sizeof(buffer[0]); diff --git a/src/rtp/net_udp.h b/src/rtp/net_udp.h index da090a31b..d61e89581 100644 --- a/src/rtp/net_udp.h +++ b/src/rtp/net_udp.h @@ -98,6 +98,8 @@ bool udp_not_empty(socket_udp *s, struct timeval *timeout); bool udp_port_pair_is_free(const char *addr, bool use_ipv6, int even_port); bool udp_is_ipv6(socket_udp *s); +void socket_error(const char *msg, ...); + /*************************************************************************************************/ #if defined(__cplusplus) }