diff --git a/src/mod/endpoints/mod_verto/mcast/mcast.c b/src/mod/endpoints/mod_verto/mcast/mcast.c index 722a3d75ca..915c831df4 100644 --- a/src/mod/endpoints/mod_verto/mcast/mcast.c +++ b/src/mod/endpoints/mod_verto/mcast/mcast.c @@ -51,6 +51,7 @@ #endif #ifndef WIN32 #include <poll.h> +#define closesocket(x) close(x) #endif #include <switch_utils.h> #include "mcast.h" @@ -67,7 +68,7 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, family = AF_INET6; } - if ((!(flags & MCAST_SEND) && !(flags & MCAST_RECV)) || (handle->sock = (int)socket(family, SOCK_DGRAM, 0)) <= 0 ) { + if ((!(flags & MCAST_SEND) && !(flags & MCAST_RECV)) || (handle->sock = (mcast_socket_t)socket(family, SOCK_DGRAM, 0)) != mcast_sock_invalid ) { return -1; } @@ -84,7 +85,7 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, } if ( setsockopt(handle->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)) != 0 ) { - close(handle->sock); + mcast_socket_close(handle); return -1; } @@ -101,14 +102,12 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, mreq.imr_interface.s_addr = htonl(INADDR_ANY); if (setsockopt(handle->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) { - close(handle->sock); - handle->sock = -1; + mcast_socket_close(handle); return -1; } if (bind(handle->sock, (struct sockaddr *) &handle->recv_addr, sizeof(handle->recv_addr)) < 0) { - close(handle->sock); - handle->sock = -1; + mcast_socket_close(handle); return -1; } @@ -139,9 +138,7 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, setsockopt(handle->sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, (const char *)&mreq, sizeof(mreq)); if (bind(handle->sock, (struct sockaddr *) &handle->recv_addr6, sizeof(handle->recv_addr6)) < 0) { - printf("FUCK (%s) %s\n", host, strerror(errno)); - close(handle->sock); - handle->sock = -1; + mcast_socket_close(handle); return -1; } } @@ -185,15 +182,15 @@ int mcast_socket_create(const char *host, int16_t port, mcast_handle_t *handle, void mcast_socket_close(mcast_handle_t *handle) { - if (handle->sock > -1) { - close(handle->sock); - handle->sock = -1; + if (handle->sock != mcast_sock_invalid) { + closesocket(handle->sock); + handle->sock = mcast_sock_invalid; } } ssize_t mcast_socket_send(mcast_handle_t *handle, void *data, size_t datalen) { - if (handle->sock <= -1) { + if (handle->sock != mcast_sock_invalid) { return -1; } diff --git a/src/mod/endpoints/mod_verto/mcast/mcast.h b/src/mod/endpoints/mod_verto/mcast/mcast.h index 8d400b613b..2bc1dfa6d4 100644 --- a/src/mod/endpoints/mod_verto/mcast/mcast.h +++ b/src/mod/endpoints/mod_verto/mcast/mcast.h @@ -69,8 +69,15 @@ extern "C" { typedef WS_SSIZE_T ssize_t; #endif +#ifndef WIN32 +typedef int mcast_socket_t; +#else +typedef SOCKET mcast_socket_t; +#endif +#define mcast_sock_invalid (mcast_socket_t)-1 + typedef struct { - int sock; + mcast_socket_t sock; unsigned char ttl; struct sockaddr_in send_addr; struct sockaddr_in recv_addr; diff --git a/src/mod/endpoints/mod_verto/mcast/mcast_cpp.cpp b/src/mod/endpoints/mod_verto/mcast/mcast_cpp.cpp index f4b3d74f30..a2793fa851 100644 --- a/src/mod/endpoints/mod_verto/mcast/mcast_cpp.cpp +++ b/src/mod/endpoints/mod_verto/mcast/mcast_cpp.cpp @@ -65,7 +65,7 @@ char *McastHandle::recv(int ms) return NULL; } -int McastHandle::filenum(void) +mcast_socket_t McastHandle::filenum(void) { return handle.sock; } diff --git a/src/mod/endpoints/mod_verto/mcast/mcast_cpp.h b/src/mod/endpoints/mod_verto/mcast/mcast_cpp.h index 0d289e755a..07062162f2 100644 --- a/src/mod/endpoints/mod_verto/mcast/mcast_cpp.h +++ b/src/mod/endpoints/mod_verto/mcast/mcast_cpp.h @@ -36,6 +36,7 @@ #ifdef __cplusplus extern "C" { +#include "mcast.h" #endif /* defined(__cplusplus) */ #if EMACS_WORKS } @@ -49,7 +50,7 @@ class McastHandle { virtual ~McastHandle(); int send(const char *data); char *recv(int ms = 0); - int filenum(void); + mcast_socket_t filenum(void); }; #ifdef __cplusplus diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index 255e95702b..ba1e78752f 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -1889,7 +1889,7 @@ static void client_run(jsock_t *jsock) if (s[0] != '#') goto nm; - switch_snprintf(repl, sizeof(repl), "#SPU %ld", (b - a) / 1000); + switch_snprintf(repl, sizeof(repl), "#SPU %ld", (long)((b - a) / 1000)); ws_write_frame(&jsock->ws, WSOC_TEXT, repl, strlen(repl)); loops = size / 1024; rem = size % 1024; @@ -1906,7 +1906,7 @@ static void client_run(jsock_t *jsock) ws_write_frame(&jsock->ws, WSOC_TEXT, repl, rem); } b = switch_time_now(); - ddur += ((b - a) / 1000); + ddur += (int)((b - a) / 1000); dur += ddur; }