http: unify client/server state machines

Type: improvement

Change-Id: I57a816fbed8b681dec201edc8d5950a34a555a2b
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
This commit is contained in:
Filip Tehlar
2023-10-30 08:21:36 +01:00
committed by Florin Coras
parent b7e66f4a30
commit b1ea30e563
3 changed files with 484 additions and 450 deletions

View File

@@ -19,6 +19,14 @@
#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);
@@ -122,6 +130,8 @@ hcc_ts_connected_callback (u32 app_index, u32 hc_index, session_t *as,
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,
@@ -207,7 +217,7 @@ hcc_ts_rx_callback (session_t *ts)
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));
@@ -229,7 +239,7 @@ hcc_ts_rx_callback (session_t *ts)
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;
}
@@ -239,6 +249,7 @@ hcc_ts_rx_callback (session_t *ts)
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)
{

File diff suppressed because it is too large Load Diff

View File

@@ -61,9 +61,13 @@ typedef enum http_conn_state_
typedef enum http_state_
{
HTTP_STATE_WAIT_METHOD,
HTTP_STATE_WAIT_APP,
HTTP_STATE_IO_MORE_DATA,
HTTP_STATE_IDLE = 0,
HTTP_STATE_WAIT_APP_METHOD,
HTTP_STATE_WAIT_CLIENT_METHOD,
HTTP_STATE_WAIT_SERVER_REPLY,
HTTP_STATE_WAIT_APP_REPLY,
HTTP_STATE_CLIENT_IO_MORE_DATA,
HTTP_STATE_APP_IO_MORE_DATA,
HTTP_N_STATES,
} http_state_t;
@@ -232,7 +236,6 @@ typedef struct http_tc_
u8 *rx_buf;
u32 rx_buf_offset;
http_buffer_t tx_buf;
u8 is_client;
u32 to_recv;
u32 bytes_dequeued;
} http_conn_t;
@@ -263,6 +266,16 @@ typedef struct http_main_
u32 fifo_size;
} http_main_t;
static inline int
http_state_is_tx_valid (http_conn_t *hc)
{
http_state_t state = hc->http_state;
return (state == HTTP_STATE_APP_IO_MORE_DATA ||
state == HTTP_STATE_CLIENT_IO_MORE_DATA ||
state == HTTP_STATE_WAIT_APP_REPLY ||
state == HTTP_STATE_WAIT_APP_METHOD);
}
#endif /* SRC_PLUGINS_HTTP_HTTP_H_ */
/*