2 * Copyright (c) 2022 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef SRC_PLUGINS_HTTP_HTTP_TIMER_H_
17 #define SRC_PLUGINS_HTTP_HTTP_TIMER_H_
19 #include <http/http.h>
20 #include <vppinfra/tw_timer_2t_1w_2048sl.h>
22 #define HTTP_CONN_TIMEOUT 60
24 typedef void (http_conn_timeout_fn) (void *);
26 typedef struct http_tw_ctx_
28 tw_timer_wheel_2t_1w_2048sl_t tw;
29 clib_spinlock_t tw_lock;
30 http_conn_timeout_fn *cb_fn;
33 extern http_tw_ctx_t http_tw_ctx;
35 void http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *cb_fn);
38 http_conn_timer_start (http_conn_t *hc)
40 http_tw_ctx_t *twc = &http_tw_ctx;
44 timeout = HTTP_CONN_TIMEOUT;
45 hs_handle = hc->c_thread_index << 24 | hc->c_c_index;
47 clib_spinlock_lock (&twc->tw_lock);
49 tw_timer_start_2t_1w_2048sl (&twc->tw, hs_handle, 0, timeout);
50 clib_spinlock_unlock (&twc->tw_lock);
54 http_conn_timer_stop (http_conn_t *hc)
56 http_tw_ctx_t *twc = &http_tw_ctx;
58 if (hc->timer_handle == ~0)
61 clib_spinlock_lock (&twc->tw_lock);
62 tw_timer_stop_2t_1w_2048sl (&twc->tw, hc->timer_handle);
63 hc->timer_handle = ~0;
64 clib_spinlock_unlock (&twc->tw_lock);
68 http_conn_timer_update (http_conn_t *hc)
70 http_tw_ctx_t *twc = &http_tw_ctx;
73 if (hc->timer_handle == ~0)
76 timeout = HTTP_CONN_TIMEOUT;
78 clib_spinlock_lock (&twc->tw_lock);
79 tw_timer_update_2t_1w_2048sl (&twc->tw, hc->timer_handle, timeout);
80 clib_spinlock_unlock (&twc->tw_lock);
83 #endif /* SRC_PLUGINS_HTTP_HTTP_TIMER_H_ */
86 * fd.io coding-style-patch-verification: ON
89 * eval: (c-set-style "gnu")