mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-15 16:39:14 +00:00
FS-9658: [mod_verto] windows fixes for mod_verto
This commit is contained in:
parent
ebda34e1d9
commit
b1206d0b50
@ -51,6 +51,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
#define closesocket(x) close(x)
|
||||||
#endif
|
#endif
|
||||||
#include <switch_utils.h>
|
#include <switch_utils.h>
|
||||||
#include "mcast.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;
|
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;
|
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 ) {
|
if ( setsockopt(handle->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)) != 0 ) {
|
||||||
close(handle->sock);
|
mcast_socket_close(handle);
|
||||||
return -1;
|
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);
|
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
|
||||||
|
|
||||||
if (setsockopt(handle->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) {
|
if (setsockopt(handle->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) {
|
||||||
close(handle->sock);
|
mcast_socket_close(handle);
|
||||||
handle->sock = -1;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bind(handle->sock, (struct sockaddr *) &handle->recv_addr, sizeof(handle->recv_addr)) < 0) {
|
if (bind(handle->sock, (struct sockaddr *) &handle->recv_addr, sizeof(handle->recv_addr)) < 0) {
|
||||||
close(handle->sock);
|
mcast_socket_close(handle);
|
||||||
handle->sock = -1;
|
|
||||||
return -1;
|
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));
|
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) {
|
if (bind(handle->sock, (struct sockaddr *) &handle->recv_addr6, sizeof(handle->recv_addr6)) < 0) {
|
||||||
printf("FUCK (%s) %s\n", host, strerror(errno));
|
mcast_socket_close(handle);
|
||||||
close(handle->sock);
|
|
||||||
handle->sock = -1;
|
|
||||||
return -1;
|
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)
|
void mcast_socket_close(mcast_handle_t *handle)
|
||||||
{
|
{
|
||||||
if (handle->sock > -1) {
|
if (handle->sock != mcast_sock_invalid) {
|
||||||
close(handle->sock);
|
closesocket(handle->sock);
|
||||||
handle->sock = -1;
|
handle->sock = mcast_sock_invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t mcast_socket_send(mcast_handle_t *handle, void *data, size_t datalen)
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,8 +69,15 @@ extern "C" {
|
|||||||
typedef WS_SSIZE_T ssize_t;
|
typedef WS_SSIZE_T ssize_t;
|
||||||
#endif
|
#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 {
|
typedef struct {
|
||||||
int sock;
|
mcast_socket_t sock;
|
||||||
unsigned char ttl;
|
unsigned char ttl;
|
||||||
struct sockaddr_in send_addr;
|
struct sockaddr_in send_addr;
|
||||||
struct sockaddr_in recv_addr;
|
struct sockaddr_in recv_addr;
|
||||||
|
@ -65,7 +65,7 @@ char *McastHandle::recv(int ms)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int McastHandle::filenum(void)
|
mcast_socket_t McastHandle::filenum(void)
|
||||||
{
|
{
|
||||||
return handle.sock;
|
return handle.sock;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
#include "mcast.h"
|
||||||
#endif /* defined(__cplusplus) */
|
#endif /* defined(__cplusplus) */
|
||||||
#if EMACS_WORKS
|
#if EMACS_WORKS
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ class McastHandle {
|
|||||||
virtual ~McastHandle();
|
virtual ~McastHandle();
|
||||||
int send(const char *data);
|
int send(const char *data);
|
||||||
char *recv(int ms = 0);
|
char *recv(int ms = 0);
|
||||||
int filenum(void);
|
mcast_socket_t filenum(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -1889,7 +1889,7 @@ static void client_run(jsock_t *jsock)
|
|||||||
|
|
||||||
if (s[0] != '#') goto nm;
|
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));
|
ws_write_frame(&jsock->ws, WSOC_TEXT, repl, strlen(repl));
|
||||||
loops = size / 1024;
|
loops = size / 1024;
|
||||||
rem = 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);
|
ws_write_frame(&jsock->ws, WSOC_TEXT, repl, rem);
|
||||||
}
|
}
|
||||||
b = switch_time_now();
|
b = switch_time_now();
|
||||||
ddur += ((b - a) / 1000);
|
ddur += (int)((b - a) / 1000);
|
||||||
dur += ddur;
|
dur += ddur;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user