diff options
author | liuyacan <liuyacan@corp.netease.com> | 2021-05-09 03:50:40 +0000 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2021-05-12 04:45:07 +0000 |
commit | 534468e9f768ae7465ef722520dadfd916cdc9fb (patch) | |
tree | 7433d66e807340a2b5e0abbe152b6b944f32675d /src/vnet/session/session.c | |
parent | 7b2917fbe2a9ec17f69ca94fcbae534927915834 (diff) |
session: support half-close connection
Some app(e.g. Envoy) may call shutdown() instead of close() when
draining connection.
Type: improvement
Signed-off-by: liuyacan <liuyacan@corp.netease.com>
Change-Id: I9543b9ca3caa87b10b134fd1fc4019124e41e4d2
Diffstat (limited to 'src/vnet/session/session.c')
-rw-r--r-- | src/vnet/session/session.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c index 1fac5ed2bb9..eba9f64ca22 100644 --- a/src/vnet/session/session.c +++ b/src/vnet/session/session.c @@ -97,9 +97,10 @@ session_send_io_evt_to_thread_custom (void *data, u32 thread_index, int session_send_ctrl_evt_to_thread (session_t * s, session_evt_type_t evt_type) { - /* only events supported are disconnect and reset */ - ASSERT (evt_type == SESSION_CTRL_EVT_CLOSE - || evt_type == SESSION_CTRL_EVT_RESET); + /* only events supported are disconnect, shutdown and reset */ + ASSERT (evt_type == SESSION_CTRL_EVT_CLOSE || + evt_type == SESSION_CTRL_EVT_HALF_CLOSE || + evt_type == SESSION_CTRL_EVT_RESET); return session_send_evt_to_thread (s, 0, s->thread_index, evt_type); } @@ -1087,7 +1088,9 @@ session_transport_closed_notify (transport_connection_t * tc) return; /* Transport thinks that app requested close but it actually didn't. - * Can happen for tcp if fin and rst are received in close succession. */ + * Can happen for tcp: + * 1)if fin and rst are received in close succession. + * 2)if app shutdown the connection. */ if (s->session_state == SESSION_STATE_READY) { session_transport_closing_notify (tc); @@ -1399,6 +1402,20 @@ session_stop_listen (session_t * s) } /** + * Initialize session half-closing procedure. + * + * Note that half-closing will not change the state of the session. + */ +void +session_half_close (session_t *s) +{ + if (!s) + return; + + session_program_transport_ctrl_evt (s, SESSION_CTRL_EVT_HALF_CLOSE); +} + +/** * Initialize session closing procedure. * * Request is always sent to session node to ensure that all outstanding @@ -1439,6 +1456,24 @@ session_reset (session_t * s) } /** + * Notify transport the session can be half-disconnected. + * + * Must be called from the session's thread. + */ +void +session_transport_half_close (session_t *s) +{ + /* Only READY session can be half-closed */ + if (s->session_state != SESSION_STATE_READY) + { + return; + } + + transport_half_close (session_get_transport_proto (s), s->connection_index, + s->thread_index); +} + +/** * Notify transport the session can be disconnected. This should eventually * result in a delete notification that allows us to cleanup session state. * Called for both active/passive disconnects. |