session: fix http server rpc to main
[vpp.git] / src / vnet / session-apps / http_server.c
index b33a086..ccbe711 100644 (file)
@@ -277,7 +277,10 @@ send_data (http_session_t * hs, u8 * data)
       /* Made any progress? */
       if (actual_transfer <= 0)
        {
+         http_server_sessions_reader_unlock ();
          vlib_process_suspend (vm, delay);
+         http_server_sessions_reader_lock ();
+
          /* 10s deadman timer */
          if (vlib_time_now (vm) > last_sent_timer + 10.0)
            {
@@ -442,7 +445,8 @@ alloc_http_process (http_server_args * args)
 
   /* Save the args (pointer) in the node runtime */
   save_args = vlib_node_get_runtime_data (vm, n->index);
-  *save_args = args;
+  *save_args = clib_mem_alloc (sizeof (*args));
+  clib_memcpy_fast (*save_args, args, sizeof (*args));
 
   vlib_start_process (vm, n->runtime_index);
 }
@@ -478,7 +482,7 @@ session_rx_request (http_session_t * hs)
 static int
 http_server_rx_callback (session_t * s)
 {
-  http_server_args *args;
+  http_server_args args;
   http_session_t *hs;
   int rv;
 
@@ -493,17 +497,17 @@ http_server_rx_callback (session_t * s)
     return rv;
 
   /* send the command to a new/recycled vlib process */
-  args = clib_mem_alloc (sizeof (*args));
-  args->hs_index = hs->session_index;
-  args->thread_index = hs->thread_index;
+  args.hs_index = hs->session_index;
+  args.thread_index = hs->thread_index;
 
   http_server_sessions_reader_unlock ();
 
-  /* Send an RPC request via the thread-0 input node */
+  /* Send RPC request to main thread */
   if (vlib_get_thread_index () != 0)
-    session_send_rpc_evt_to_thread (0, alloc_http_process_callback, args);
+    vlib_rpc_call_main_thread (alloc_http_process_callback, (u8 *) & args,
+                              sizeof (args));
   else
-    alloc_http_process (args);
+    alloc_http_process (&args);
   return 0;
 }
 
@@ -770,6 +774,7 @@ http_server_create_command_fn (vlib_main_t * vm,
                               vlib_cli_command_t * cmd)
 {
   http_server_main_t *hsm = &http_server_main;
+  unformat_input_t _line_input, *line_input = &_line_input;
   u64 seg_size;
   u8 *html;
   int rv;
@@ -778,13 +783,19 @@ http_server_create_command_fn (vlib_main_t * vm,
   hsm->private_segment_size = 0;
   hsm->fifo_size = 0;
   hsm->is_static = 0;
-  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+
+  /* Get a line of input. */
+  if (!unformat_user (input, unformat_line_input, line_input))
+    goto start_server;
+
+  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
     {
-      if (unformat (input, "static"))
+      if (unformat (line_input, "static"))
        hsm->is_static = 1;
-      else if (unformat (input, "prealloc-fifos %d", &hsm->prealloc_fifos))
+      else
+       if (unformat (line_input, "prealloc-fifos %d", &hsm->prealloc_fifos))
        ;
-      else if (unformat (input, "private-segment-size %U",
+      else if (unformat (line_input, "private-segment-size %U",
                         unformat_memory_size, &seg_size))
        {
          if (seg_size >= 0x100000000ULL)
@@ -795,14 +806,18 @@ http_server_create_command_fn (vlib_main_t * vm,
            }
          hsm->private_segment_size = seg_size;
        }
-      else if (unformat (input, "fifo-size %d", &hsm->fifo_size))
+      else if (unformat (line_input, "fifo-size %d", &hsm->fifo_size))
        hsm->fifo_size <<= 10;
-      else if (unformat (input, "uri %s", &hsm->uri))
+      else if (unformat (line_input, "uri %s", &hsm->uri))
        ;
       else
        return clib_error_return (0, "unknown input `%U'",
-                                 format_unformat_error, input);
+                                 format_unformat_error, line_input);
     }
+  unformat_free (line_input);
+
+start_server:
+
   if (hsm->my_client_index != (u32) ~ 0)
     return clib_error_return (0, "test http server is already running");