C websockify: add --run-once option.
This commit is contained in:
@@ -754,11 +754,23 @@ void start_server() {
|
|||||||
handler_msg("got client connection from %s\n",
|
handler_msg("got client connection from %s\n",
|
||||||
inet_ntoa(cli_addr.sin_addr));
|
inet_ntoa(cli_addr.sin_addr));
|
||||||
|
|
||||||
|
if (!settings.run_once) {
|
||||||
handler_msg("forking handler process\n");
|
handler_msg("forking handler process\n");
|
||||||
pid = fork();
|
pid = fork();
|
||||||
|
}
|
||||||
|
|
||||||
if (pid == 0) { // handler process
|
if (pid == 0) { // handler process
|
||||||
ws_ctx = do_handshake(csock);
|
ws_ctx = do_handshake(csock);
|
||||||
|
if (settings.run_once) {
|
||||||
|
if (ws_ctx == NULL) {
|
||||||
|
// Not a real WebSocket connection
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
// Successful connection, stop listening for new
|
||||||
|
// connections
|
||||||
|
close(lsock);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ws_ctx == NULL) {
|
if (ws_ctx == NULL) {
|
||||||
handler_msg("No connection after handshake\n");
|
handler_msg("No connection after handshake\n");
|
||||||
break; // Child process exits
|
break; // Child process exits
|
||||||
|
@@ -61,6 +61,7 @@ typedef struct {
|
|||||||
char *key;
|
char *key;
|
||||||
int ssl_only;
|
int ssl_only;
|
||||||
int daemon;
|
int daemon;
|
||||||
|
int run_once;
|
||||||
} settings_t;
|
} settings_t;
|
||||||
|
|
||||||
|
|
||||||
|
@@ -274,13 +274,14 @@ void proxy_handler(ws_ctx_t *ws_ctx) {
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd, c, option_index = 0;
|
int fd, c, option_index = 0;
|
||||||
static int ssl_only = 0, daemon = 0, verbose = 0;
|
static int ssl_only = 0, daemon = 0, run_once = 0, verbose = 0;
|
||||||
char *found;
|
char *found;
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"verbose", no_argument, &verbose, 'v'},
|
{"verbose", no_argument, &verbose, 'v'},
|
||||||
{"ssl-only", no_argument, &ssl_only, 1 },
|
{"ssl-only", no_argument, &ssl_only, 1 },
|
||||||
{"daemon", no_argument, &daemon, 'D'},
|
{"daemon", no_argument, &daemon, 'D'},
|
||||||
/* ---- */
|
/* ---- */
|
||||||
|
{"run-once", no_argument, 0, 'r'},
|
||||||
{"cert", required_argument, 0, 'c'},
|
{"cert", required_argument, 0, 'c'},
|
||||||
{"key", required_argument, 0, 'k'},
|
{"key", required_argument, 0, 'k'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
@@ -294,7 +295,7 @@ int main(int argc, char *argv[])
|
|||||||
settings.key = "";
|
settings.key = "";
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
c = getopt_long (argc, argv, "vDc:k:",
|
c = getopt_long (argc, argv, "vDrc:k:",
|
||||||
long_options, &option_index);
|
long_options, &option_index);
|
||||||
|
|
||||||
/* Detect the end */
|
/* Detect the end */
|
||||||
@@ -311,6 +312,9 @@ int main(int argc, char *argv[])
|
|||||||
case 'D':
|
case 'D':
|
||||||
daemon = 1;
|
daemon = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
run_once = 1;
|
||||||
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
settings.cert = realpath(optarg, NULL);
|
settings.cert = realpath(optarg, NULL);
|
||||||
if (! settings.cert) {
|
if (! settings.cert) {
|
||||||
@@ -330,6 +334,7 @@ int main(int argc, char *argv[])
|
|||||||
settings.verbose = verbose;
|
settings.verbose = verbose;
|
||||||
settings.ssl_only = ssl_only;
|
settings.ssl_only = ssl_only;
|
||||||
settings.daemon = daemon;
|
settings.daemon = daemon;
|
||||||
|
settings.run_once = run_once;
|
||||||
|
|
||||||
if ((argc-optind) != 2) {
|
if ((argc-optind) != 2) {
|
||||||
usage("Invalid number of arguments\n");
|
usage("Invalid number of arguments\n");
|
||||||
@@ -370,6 +375,7 @@ int main(int argc, char *argv[])
|
|||||||
//printf(" verbose: %d\n", settings.verbose);
|
//printf(" verbose: %d\n", settings.verbose);
|
||||||
//printf(" ssl_only: %d\n", settings.ssl_only);
|
//printf(" ssl_only: %d\n", settings.ssl_only);
|
||||||
//printf(" daemon: %d\n", settings.daemon);
|
//printf(" daemon: %d\n", settings.daemon);
|
||||||
|
//printf(" run_once: %d\n", settings.run_once);
|
||||||
//printf(" cert: %s\n", settings.cert);
|
//printf(" cert: %s\n", settings.cert);
|
||||||
//printf(" key: %s\n", settings.key);
|
//printf(" key: %s\n", settings.key);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user