From 1c95be3bbe4434d3edf2432fb07cd1d7e156b8db Mon Sep 17 00:00:00 2001 From: Juan Navarro Date: Thu, 12 Apr 2018 12:55:46 +0200 Subject: [PATCH] Change default listen backlog to socket_base::max_connections Work on #245 Related to zaphoyd/websocketpp#549 Change default listen backlog from 0 to boost::asio::socket_base::max_connections. Also, we'll take on the opportunity and add a configuration parameter for this value, in the file kurento.conf.json. --- kurento.conf.json | 5 ++++- server/transport/websocket/WebSocketTransport.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/kurento.conf.json b/kurento.conf.json index e95469d17..c3da6f7e9 100644 --- a/kurento.conf.json +++ b/kurento.conf.json @@ -21,7 +21,10 @@ // "localAddress": "localhost" //}, "path": "kurento", - "threads": 10 + "threads": 10, + // Maximum queue length of pending connections (see sysctl tcp_max_syn_backlog) + // Default SOMAXCONN (128) + //"connqueue": 128, } } } diff --git a/server/transport/websocket/WebSocketTransport.cpp b/server/transport/websocket/WebSocketTransport.cpp index d85e8ccb7..bd2ede565 100644 --- a/server/transport/websocket/WebSocketTransport.cpp +++ b/server/transport/websocket/WebSocketTransport.cpp @@ -47,6 +47,8 @@ const std::string DEFAULT_LOCAL_ADDRESS = "localhost"; const ushort WEBSOCKET_PORT_DEFAULT = 8888; const std::string WEBSOCKET_PATH_DEFAULT = "kurento"; const int WEBSOCKET_THREADS_DEFAULT = 10; +const int WEBSOCKET_CONNQUEUE_DEFAULT = + boost::asio::socket_base::max_connections; class configuration_exception : public std::exception { @@ -71,6 +73,7 @@ WebSocketTransport::WebSocketTransport (const boost::property_tree::ptree { ushort port; ushort securePort; + int connqueue; std::string registrarAddress; std::string localAddress; @@ -81,6 +84,9 @@ WebSocketTransport::WebSocketTransport (const boost::property_tree::ptree path = config.get ("mediaServer.net.websocket.path", WEBSOCKET_PATH_DEFAULT); + connqueue = config.get ("mediaServer.net.websocket.connqueue", + WEBSOCKET_CONNQUEUE_DEFAULT); + try { n_threads = config.get ("mediaServer.net.websocket.threads"); @@ -103,6 +109,7 @@ WebSocketTransport::WebSocketTransport (const boost::property_tree::ptree server.clear_error_channels (websocketpp::log::alevel::all); server.init_asio (&ios); + server.set_listen_backlog (connqueue); server.set_reuse_addr (true); server.set_open_handler (std::bind ( (void (WebSocketTransport::*) ( WebSocketServer *, websocketpp::connection_hdl) )