Skip to content

Commit

Permalink
Set libmicrohttpd connections limit in http transport configuration. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
atoppi committed Dec 15, 2020
1 parent e82a06b commit b4f69c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions conf/janus.transport.http.jcfg.sample
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ general: {
#secure_interface = "eth0" # Whether we should bind this server to a specific interface only
#secure_ip = "192.168.0.1" # Whether we should bind this server to a specific IP address (v4 or v6) only
#acl = "127.,192.168.0." # Only allow requests coming from this comma separated list of addresses
#mhd_connection_limit = 1020 # Open connections limit in libmicrohttpd (default=1020)
#mhd_debug = false # Ask libmicrohttpd to write warning and error messages to stderr (default=false)
}

Expand Down
13 changes: 13 additions & 0 deletions transports/janus_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ janus_transport *create(void) {
return &janus_http_transport;
}

/* MHD uses this value as default */
#define DEFAULT_CONNECTION_LIMIT (FD_SETSIZE-4)
static unsigned int connection_limit = DEFAULT_CONNECTION_LIMIT;

/* Useful stuff */
static gint initialized = 0, stopping = 0;
Expand Down Expand Up @@ -504,6 +507,7 @@ static struct MHD_Daemon *janus_http_create_daemon(gboolean admin, char *path,
path,
MHD_OPTION_NOTIFY_COMPLETED, &janus_http_request_completed, NULL,
MHD_OPTION_CONNECTION_TIMEOUT, 120,
MHD_OPTION_CONNECTION_LIMIT, connection_limit,
MHD_OPTION_END);
} else {
/* Bind to the interface that was specified */
Expand All @@ -520,6 +524,7 @@ static struct MHD_Daemon *janus_http_create_daemon(gboolean admin, char *path,
MHD_OPTION_NOTIFY_COMPLETED, &janus_http_request_completed, NULL,
MHD_OPTION_SOCK_ADDR, ipv6 ? (struct sockaddr *)&addr6 : (struct sockaddr *)&addr,
MHD_OPTION_CONNECTION_TIMEOUT, 120,
MHD_OPTION_CONNECTION_LIMIT, connection_limit,
MHD_OPTION_END);
}
} else {
Expand All @@ -545,6 +550,7 @@ static struct MHD_Daemon *janus_http_create_daemon(gboolean admin, char *path,
MHD_OPTION_HTTPS_MEM_KEY, cert_key_bytes,
MHD_OPTION_HTTPS_KEY_PASSWORD, password,
MHD_OPTION_CONNECTION_TIMEOUT, 120,
MHD_OPTION_CONNECTION_LIMIT, connection_limit,
MHD_OPTION_END);
} else {
/* Bind to the interface that was specified */
Expand All @@ -565,6 +571,7 @@ static struct MHD_Daemon *janus_http_create_daemon(gboolean admin, char *path,
MHD_OPTION_HTTPS_KEY_PASSWORD, password,
MHD_OPTION_SOCK_ADDR, ipv6 ? (struct sockaddr *)&addr6 : (struct sockaddr *)&addr,
MHD_OPTION_CONNECTION_TIMEOUT, 120,
MHD_OPTION_CONNECTION_LIMIT, connection_limit,
MHD_OPTION_END);
}
}
Expand Down Expand Up @@ -700,6 +707,12 @@ int janus_http_init(janus_transport_callbacks *callback, const char *config_path
} else {
admin_ws_path = g_strdup("/admin");
}
/* Check the open connections limit for mhd */
item = janus_config_get(config, config_general, janus_config_type_item, "mhd_connection_limit");
if(item && item->value && janus_string_to_uint32(item->value, &connection_limit) < 0) {
JANUS_LOG(LOG_ERR, "Invalid mhd_connection_limit (%s), falling back to default\n", item->value);
connection_limit = DEFAULT_CONNECTION_LIMIT;
}
/* Should we set the debug flag in libmicrohttpd? */
item = janus_config_get(config, config_general, janus_config_type_item, "mhd_debug");
if(item && item->value && janus_is_true(item->value))
Expand Down

0 comments on commit b4f69c0

Please sign in to comment.