Websocket stdio / websocketd experiment
authorBill Erickson <berickxx@gmail.com>
Mon, 11 Jun 2018 15:12:26 +0000 (11:12 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 11 Jun 2018 15:12:26 +0000 (11:12 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
src/websocket-stdio/osrf-websocket-stdio.c

index 68cde32..3ea2825 100644 (file)
  *
  * Built to function with websocketd:
  * https://github.com/joewalnes/websocketd
+ *
+ * Synopsis:
+ *
+ * websocketd --port 7684 --max-forks 250 ./osrf-websocket-stdio /path/to/opensrf_core.xml &
+ *
  */
 
 #include <stdio.h>
@@ -58,7 +63,7 @@
 #define RESET_MESSAGE_SIZE 102400
 
 // default values, replaced during setup (below) as needed.
-static char* config_file = "/openils/conf/opensrf_core.xml"; // TODO
+static char* config_file = "/openils/conf/opensrf_core.xml"; 
 static char* config_ctxt = "gateway";
 static char* osrf_router = NULL;
 static char* osrf_domain = NULL;
@@ -72,7 +77,7 @@ static char recipient_buf[RECIP_BUF_SIZE]; // reusable recipient buffer
 static char* client_ip = NULL;
 
 static void rebuild_stdin_buffer();
-static void child_init();
+static void child_init(int argc, char* argv[]);
 static void read_from_stdin();
 static void relay_stdin_message(const char*);
 static char* extract_inbound_messages();
@@ -87,7 +92,7 @@ static void sigint_handler(int sig) {
     shut_it_down(0);
 }
 
-int main() {
+int main(int argc, char* argv[]) {
 
     // Handle shutdown signal
     signal(SIGINT, sigint_handler);
@@ -96,7 +101,7 @@ int main() {
 
     // Connect to OpenSRF
     // exits on error.
-    child_init();
+    child_init(argc, argv);
 
     // Disable output buffering.
     setbuf(stdout, NULL);
@@ -170,7 +175,11 @@ static int shut_it_down(int stat) {
 
 
 // Connect to opensrf
-static void child_init() {
+static void child_init(int argc, char* argv[]) {
+
+    if (argc > 1) {
+        config_file = argv[1];
+    }
 
     if (!osrf_system_bootstrap_client(config_file, config_ctxt) ) {
         fprintf(stderr, "Cannot boostrap OSRF\n");