http: add http protocol plugin
Basic HTTP/1.1 server side implementation. Type: feature Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I06bddaf7f11e28db802b4cd7ef8160c78cb019b6
This commit is contained in:
91
src/plugins/http/http_timer.c
Normal file
91
src/plugins/http/http_timer.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Cisco and/or its affiliates.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <http/http_timer.h>
|
||||
#include <vnet/session/session.h>
|
||||
|
||||
http_tw_ctx_t http_tw_ctx;
|
||||
|
||||
static void
|
||||
http_timer_process_expired_cb (u32 *expired_timers)
|
||||
{
|
||||
http_tw_ctx_t *twc = &http_tw_ctx;
|
||||
u32 hs_handle;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < vec_len (expired_timers); i++)
|
||||
{
|
||||
/* Get session handle. The first bit is the timer id */
|
||||
hs_handle = expired_timers[i] & 0x7FFFFFFF;
|
||||
session_send_rpc_evt_to_thread (hs_handle >> 24, twc->cb_fn,
|
||||
uword_to_pointer (hs_handle, void *));
|
||||
}
|
||||
}
|
||||
|
||||
static uword
|
||||
http_timer_process (vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
|
||||
{
|
||||
http_tw_ctx_t *twc = &http_tw_ctx;
|
||||
f64 now, timeout = 1.0;
|
||||
uword *event_data = 0;
|
||||
uword __clib_unused event_type;
|
||||
|
||||
while (1)
|
||||
{
|
||||
vlib_process_wait_for_event_or_clock (vm, timeout);
|
||||
now = vlib_time_now (vm);
|
||||
event_type = vlib_process_get_events (vm, (uword **) &event_data);
|
||||
|
||||
/* expire timers */
|
||||
clib_spinlock_lock (&twc->tw_lock);
|
||||
tw_timer_expire_timers_2t_1w_2048sl (&twc->tw, now);
|
||||
clib_spinlock_unlock (&twc->tw_lock);
|
||||
|
||||
vec_reset_length (event_data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
VLIB_REGISTER_NODE (http_timer_process_node) = {
|
||||
.function = http_timer_process,
|
||||
.type = VLIB_NODE_TYPE_PROCESS,
|
||||
.name = "http-timer-process",
|
||||
.state = VLIB_NODE_STATE_DISABLED,
|
||||
};
|
||||
|
||||
void
|
||||
http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *cb_fn)
|
||||
{
|
||||
http_tw_ctx_t *twc = &http_tw_ctx;
|
||||
vlib_node_t *n;
|
||||
|
||||
tw_timer_wheel_init_2t_1w_2048sl (&twc->tw, http_timer_process_expired_cb,
|
||||
1.0 /* timer interval */, ~0);
|
||||
clib_spinlock_init (&twc->tw_lock);
|
||||
twc->cb_fn = cb_fn;
|
||||
|
||||
vlib_node_set_state (vm, http_timer_process_node.index,
|
||||
VLIB_NODE_STATE_POLLING);
|
||||
n = vlib_get_node (vm, http_timer_process_node.index);
|
||||
vlib_start_process (vm, n->runtime_index);
|
||||
}
|
||||
|
||||
/*
|
||||
* fd.io coding-style-patch-verification: ON
|
||||
*
|
||||
* Local Variables:
|
||||
* eval: (c-set-style "gnu")
|
||||
* End:
|
||||
*/
|
Reference in New Issue
Block a user