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",
|
||||
inet_ntoa(cli_addr.sin_addr));
|
||||
|
||||
handler_msg("forking handler process\n");
|
||||
pid = fork();
|
||||
if (!settings.run_once) {
|
||||
handler_msg("forking handler process\n");
|
||||
pid = fork();
|
||||
}
|
||||
|
||||
if (pid == 0) { // handler process
|
||||
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) {
|
||||
handler_msg("No connection after handshake\n");
|
||||
break; // Child process exits
|
||||
|
@@ -61,6 +61,7 @@ typedef struct {
|
||||
char *key;
|
||||
int ssl_only;
|
||||
int daemon;
|
||||
int run_once;
|
||||
} settings_t;
|
||||
|
||||
|
||||
|
@@ -274,13 +274,14 @@ void proxy_handler(ws_ctx_t *ws_ctx) {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
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;
|
||||
static struct option long_options[] = {
|
||||
{"verbose", no_argument, &verbose, 'v'},
|
||||
{"ssl-only", no_argument, &ssl_only, 1 },
|
||||
{"daemon", no_argument, &daemon, 'D'},
|
||||
/* ---- */
|
||||
{"run-once", no_argument, 0, 'r'},
|
||||
{"cert", required_argument, 0, 'c'},
|
||||
{"key", required_argument, 0, 'k'},
|
||||
{0, 0, 0, 0}
|
||||
@@ -294,7 +295,7 @@ int main(int argc, char *argv[])
|
||||
settings.key = "";
|
||||
|
||||
while (1) {
|
||||
c = getopt_long (argc, argv, "vDc:k:",
|
||||
c = getopt_long (argc, argv, "vDrc:k:",
|
||||
long_options, &option_index);
|
||||
|
||||
/* Detect the end */
|
||||
@@ -311,6 +312,9 @@ int main(int argc, char *argv[])
|
||||
case 'D':
|
||||
daemon = 1;
|
||||
break;
|
||||
case 'r':
|
||||
run_once = 1;
|
||||
break;
|
||||
case 'c':
|
||||
settings.cert = realpath(optarg, NULL);
|
||||
if (! settings.cert) {
|
||||
@@ -330,6 +334,7 @@ int main(int argc, char *argv[])
|
||||
settings.verbose = verbose;
|
||||
settings.ssl_only = ssl_only;
|
||||
settings.daemon = daemon;
|
||||
settings.run_once = run_once;
|
||||
|
||||
if ((argc-optind) != 2) {
|
||||
usage("Invalid number of arguments\n");
|
||||
@@ -370,6 +375,7 @@ int main(int argc, char *argv[])
|
||||
//printf(" verbose: %d\n", settings.verbose);
|
||||
//printf(" ssl_only: %d\n", settings.ssl_only);
|
||||
//printf(" daemon: %d\n", settings.daemon);
|
||||
//printf(" run_once: %d\n", settings.run_once);
|
||||
//printf(" cert: %s\n", settings.cert);
|
||||
//printf(" key: %s\n", settings.key);
|
||||
|
||||
|
Reference in New Issue
Block a user