From f3ad9540fa1e53d703a6839cc80ceff511648fc0 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 21 Dec 2016 09:32:44 +0800 Subject: [PATCH] ssl-server: Add CONTEXT_PORT_NO_LISTEN_SERVER Special port setting to disable listening for a server using socket adoption. This contrasts with CONTEXT_PORT_NO_LISTEN which does the same for a client. In particular, server-side SSL is not disabled by CONTEXT_PORT_NO_LISTEN_SERVER as it is by CONTEXT_PORT_NO_LISTEN. --- lib/libwebsockets.h | 9 +++++---- lib/server.c | 2 +- lib/ssl-server.c | 1 - 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index d7f7df6f0..be8743304 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -253,6 +253,7 @@ typedef ssl_context SSL; #define CONTEXT_PORT_NO_LISTEN -1 +#define CONTEXT_PORT_NO_LISTEN_SERVER -2 /** \defgroup log Logging * @@ -1560,10 +1561,10 @@ enum lws_context_options { */ struct lws_context_creation_info { int port; - /**< VHOST: Port to listen on... you can use CONTEXT_PORT_NO_LISTEN to - * suppress listening on any port, that's what you want if you are - * not running a websocket server at all but just using it as a - * client */ + /**< VHOST: Port to listen on. Use CONTEXT_PORT_NO_LISTEN to suppress + * listening for a client. Use CONTEXT_PORT_NO_LISTEN_SERVER if you are + * writing a server but you are using \ref sock-adopt instead of the + * built-in listener */ const char *iface; /**< VHOST: NULL to bind the listen socket to all interfaces, or the * interface name, eg, "eth2" diff --git a/lib/server.c b/lib/server.c index bc9033a7c..cfb08312a 100644 --- a/lib/server.c +++ b/lib/server.c @@ -44,7 +44,7 @@ lws_context_init_server(struct lws_context_creation_info *info, /* set up our external listening socket we serve on */ - if (info->port == CONTEXT_PORT_NO_LISTEN) + if (info->port == CONTEXT_PORT_NO_LISTEN || info->port == CONTEXT_PORT_NO_LISTEN_SERVER) return 0; vh = vhost->context->vhost_list; diff --git a/lib/ssl-server.c b/lib/ssl-server.c index b1e217416..d458a002a 100644 --- a/lib/ssl-server.c +++ b/lib/ssl-server.c @@ -211,7 +211,6 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info, vhost->use_ssl = 0; return 0; } - if (info->port != CONTEXT_PORT_NO_LISTEN) { vhost->use_ssl = info->ssl_cert_filepath != NULL;