1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

disable private broadcast sockets if enable no fork config option

The whole thing about count_protocols + 1 broadcast sockets and
associated dummy wsis is a workaround for getting a broadcast from
a different process context, if we are running with --enable-no-fork
then we don't need any of it in.

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2013-01-21 09:09:52 +08:00
parent 596b220c40
commit f5bc1306ef
4 changed files with 21 additions and 2 deletions

View file

@ -1410,11 +1410,14 @@ libwebsocket_create_context(int port, const char *interf,
void *user)
{
int n;
int fd;
struct sockaddr_in serv_addr, cli_addr;
struct sockaddr_in serv_addr;
int opt = 1;
struct libwebsocket_context *context = NULL;
#ifndef LWS_NO_FORK
unsigned int slen;
struct sockaddr_in cli_addr;
int fd;
#endif
char *p;
struct libwebsocket *wsi;
#ifndef LWS_NO_EXTENSIONS
@ -1866,6 +1869,7 @@ libwebsocket_create_context(int port, const char *interf,
protocols[context->count_protocols].protocol_index =
context->count_protocols;
#ifndef LWS_NO_FORK
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) {
lwsl_err("ERROR opening socket\n");
@ -1921,7 +1925,9 @@ libwebsocket_create_context(int port, const char *interf,
context->count_protocols;
insert_wsi_socket_into_fds(context, wsi);
#endif
}
#ifndef LWS_NO_EXTENSIONS
/*
* give all extensions a chance to create any per-context
@ -2083,7 +2089,12 @@ libwebsockets_broadcast(const struct libwebsocket_protocols *protocol,
int n;
struct libwebsocket *wsi;
if (!context)
return 1;
#ifndef LWS_NO_FORK
if (!protocol->broadcast_socket_user_fd) {
#endif
/*
* We are either running unforked / flat, or we are being
* called from poll thread context
@ -2125,6 +2136,7 @@ libwebsockets_broadcast(const struct libwebsocket_protocols *protocol,
}
return 0;
#ifndef LWS_NO_FORK
}
/*
@ -2140,6 +2152,7 @@ libwebsockets_broadcast(const struct libwebsocket_protocols *protocol,
n = send(protocol->broadcast_socket_user_fd, buf, len, MSG_NOSIGNAL);
return n;
#endif
}
int

View file

@ -321,7 +321,9 @@ struct libwebsocket {
LWS_SEND_BUFFER_POST_PADDING];
int rx_user_buffer_head;
enum libwebsocket_write_protocol rx_frame_type;
#ifndef LWS_NO_FORK
int protocol_index_for_broadcast_proxy;
#endif
enum pending_timeout pending_timeout;
unsigned long pending_timeout_limit;

View file

@ -297,6 +297,7 @@ int lws_server_socket_service(struct libwebsocket_context *context,
insert_wsi_socket_into_fds(context, new_wsi);
break;
#ifndef LWS_NO_FORK
case LWS_CONNMODE_BROADCAST_PROXY_LISTENER:
/* as we are listening, POLLIN means accept() is needed */
@ -418,6 +419,7 @@ bail_prox_listener:
buf + LWS_SEND_BUFFER_PRE_PADDING, len);
}
break;
#endif
default:
break;
}

View file

@ -33,7 +33,9 @@
static int close_testing;
#ifdef EXTERNAL_POLL
#ifndef LWS_NO_FORK
#define LWS_NO_FORK
#endif
int max_poll_elements;