#include <http/http.h>
#include <hs_apps/http_cli.h>
+#define HCC_DEBUG 0
+
+#if HCC_DEBUG
+#define HCC_DBG(_fmt, _args...) clib_warning (_fmt, ##_args)
+#else
+#define HCC_DBG(_fmt, _args...)
+#endif
+
typedef struct
{
CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
vlib_main_t *vlib_main;
u32 cli_node_index;
u8 *http_response;
+ u8 *appns_id;
+ u64 appns_secret;
} hcc_main_t;
typedef enum
http_msg_t msg;
int rv;
+ HCC_DBG ("hc_index: %d", hc_index);
+
if (err)
{
clib_warning ("connected error: hc_index(%d): %U", hc_index,
return 0;
}
- if (!hs->to_recv)
+ if (hs->to_recv == 0)
{
rv = svm_fifo_dequeue (ts->rx_fifo, sizeof (msg), (u8 *) &msg);
ASSERT (rv == sizeof (msg));
rv = svm_fifo_dequeue (ts->rx_fifo, n_deq, hcm->http_response + curr);
if (rv < 0)
{
- clib_warning ("app dequeue failed");
+ clib_warning ("app dequeue(n=%d) failed; rv = %d", n_deq, rv);
return -1;
}
vec_set_len (hcm->http_response, curr + n_deq);
ASSERT (hs->to_recv >= rv);
hs->to_recv -= rv;
+ HCC_DBG ("app rcvd %d, remains %d", rv, hs->to_recv);
if (hs->to_recv == 0)
{
hcm->fifo_size ? hcm->fifo_size : 32 << 10;
a->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN;
a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = hcm->prealloc_fifos;
+ if (hcm->appns_id)
+ {
+ a->namespace_id = hcm->appns_id;
+ a->options[APP_OPTIONS_NAMESPACE_SECRET] = hcm->appns_secret;
+ }
if ((rv = vnet_application_attach (a)))
return clib_error_return (0, "attach returned %d", rv);
return 0;
}
+static int
+hcc_connect_rpc (void *rpc_args)
+{
+ vnet_connect_args_t *a = rpc_args;
+ int rv;
+
+ rv = vnet_connect (a);
+ if (rv)
+ clib_warning (0, "connect returned: %U", format_session_error, rv);
+
+ vec_free (a);
+ return rv;
+}
+
+static void
+hcc_program_connect (vnet_connect_args_t *a)
+{
+ session_send_rpc_evt_to_thread_force (transport_cl_thread (),
+ hcc_connect_rpc, a);
+}
+
static clib_error_t *
hcc_connect ()
{
- vnet_connect_args_t _a = {}, *a = &_a;
+ vnet_connect_args_t *a = 0;
hcc_main_t *hcm = &hcc_main;
hcc_worker_t *wrk;
hcc_session_t *hs;
+ vec_validate (a, 0);
+ clib_memset (a, 0, sizeof (a[0]));
+
clib_memcpy (&a->sep_ext, &hcm->connect_sep, sizeof (hcm->connect_sep));
a->app_index = hcm->app_index;
hs = hcc_session_alloc (wrk);
a->api_context = hs->session_index;
- int rv = vnet_connect (a);
-
- if (rv)
- return clib_error_return (0, "connect returned: %U", format_session_error,
- rv);
+ hcc_program_connect (a);
return 0;
}
unformat_input_t _line_input, *line_input = &_line_input;
hcc_main_t *hcm = &hcc_main;
u64 seg_size;
+ u8 *appns_id = 0;
clib_error_t *err = 0;
int rv;
hcm->fifo_size <<= 10;
else if (unformat (line_input, "uri %s", &hcm->uri))
;
+ else if (unformat (line_input, "appns %_%v%_", &appns_id))
+ ;
+ else if (unformat (line_input, "secret %lu", &hcm->appns_secret))
+ ;
else if (unformat (line_input, "query %s", &hcm->http_query))
;
else
}
}
+ vec_free (hcm->appns_id);
+ hcm->appns_id = appns_id;
hcm->cli_node_index = vlib_get_current_process (vm)->node_runtime.node_index;
if (!hcm->uri)
goto done;
}
+ vlib_worker_thread_barrier_sync (vm);
vnet_session_enable_disable (vm, 1 /* turn on TCP, etc. */);
+ vlib_worker_thread_barrier_release (vm);
err = hcc_run (vm);
VLIB_CLI_COMMAND (hcc_command, static) = {
.path = "http cli client",
- .short_help = "uri http://<ip-addr> query <query-string>",
+ .short_help = "[appns <app-ns> secret <appns-secret>] uri http://<ip-addr> "
+ "query <query-string>",
.function = hcc_command_fn,
+ .is_mp_safe = 1,
};
static clib_error_t *