From: Christopher Faulet Date: Thu, 31 Mar 2022 07:47:24 +0000 (+0200) Subject: MINOR: stream-int/stream: Move si_retnclose() in the stream scope X-Git-Tag: v2.6-dev6~73 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9125f3cc7733fc88517dc7c2a8d8decea505e0d1;p=thirdparty%2Fhaproxy.git MINOR: stream-int/stream: Move si_retnclose() in the stream scope si_retnclose() is used to send a reply to a client before closing. There is no use on the server side, in spite of the function is generic. Thus, it is renamed stream_retnclose() and moved into the stream scope. The function now handle a stream and explicitly send a message to the client. --- diff --git a/include/haproxy/stream.h b/include/haproxy/stream.h index 6cf8d14e60..32070178a5 100644 --- a/include/haproxy/stream.h +++ b/include/haproxy/stream.h @@ -367,6 +367,7 @@ static inline int stream_check_conn_timeout(struct stream *s) } int stream_set_timeout(struct stream *s, enum act_timeout_name name, int timeout); +void stream_retnclose(struct stream *s, const struct buffer *msg); void service_keywords_register(struct action_kw_list *kw_list); struct action_kw *service_find(const char *kw); diff --git a/include/haproxy/stream_interface.h b/include/haproxy/stream_interface.h index 9747d2ce4f..0085de8efc 100644 --- a/include/haproxy/stream_interface.h +++ b/include/haproxy/stream_interface.h @@ -40,8 +40,6 @@ struct stream_interface *si_new(struct conn_stream *cs); void si_free(struct stream_interface *si); /* main event functions used to move data between sockets and buffers */ - -void si_retnclose(struct stream_interface *si, const struct buffer *msg); int conn_si_send_proxy(struct connection *conn, unsigned int flag); struct appctx *si_register_handler(struct stream_interface *si, struct applet *app); void si_applet_wake_cb(struct stream_interface *si); diff --git a/src/cli.c b/src/cli.c index 5ed96f5407..baea805e16 100644 --- a/src/cli.c +++ b/src/cli.c @@ -2200,7 +2200,7 @@ void pcli_reply_and_close(struct stream *s, const char *msg) struct buffer *buf = get_trash_chunk(); chunk_initstr(buf, msg); - si_retnclose(cs_si(s->csf), buf); + stream_retnclose(s, buf); } static enum obj_type *pcli_pid_to_server(int proc_pid) diff --git a/src/stream.c b/src/stream.c index d865125356..ec6e1f620c 100644 --- a/src/stream.c +++ b/src/stream.c @@ -832,6 +832,35 @@ void stream_process_counters(struct stream *s) } } +/* + * Returns a message to the client ; the connection is shut down for read, + * and the request is cleared so that no server connection can be initiated. + * The buffer is marked for read shutdown on the other side to protect the + * message, and the buffer write is enabled. The message is contained in a + * "chunk". If it is null, then an empty message is used. The reply buffer does + * not need to be empty before this, and its contents will not be overwritten. + * The primary goal of this function is to return error messages to a client. + */ +void stream_retnclose(struct stream *s, const struct buffer *msg) +{ + struct channel *ic = &s->req; + struct channel *oc = &s->res; + + channel_auto_read(ic); + channel_abort(ic); + channel_auto_close(ic); + channel_erase(ic); + channel_truncate(oc); + + if (likely(msg && msg->data)) + co_inject(oc, msg->area, msg->data); + + oc->wex = tick_add_ifset(now_ms, oc->wto); + channel_auto_read(oc); + channel_auto_close(oc); + channel_shutr_now(oc); +} + int stream_set_timeout(struct stream *s, enum act_timeout_name name, int timeout) { switch (name) { diff --git a/src/stream_interface.c b/src/stream_interface.c index 9bcfb2c8a9..ca7c616ec9 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -128,36 +128,6 @@ void si_free(struct stream_interface *si) pool_free(pool_head_streaminterface, si); } -/* - * Returns a message to the client ; the connection is shut down for read, - * and the request is cleared so that no server connection can be initiated. - * The buffer is marked for read shutdown on the other side to protect the - * message, and the buffer write is enabled. The message is contained in a - * "chunk". If it is null, then an empty message is used. The reply buffer does - * not need to be empty before this, and its contents will not be overwritten. - * The primary goal of this function is to return error messages to a client. - */ -void si_retnclose(struct stream_interface *si, - const struct buffer *msg) -{ - struct channel *ic = si_ic(si); - struct channel *oc = si_oc(si); - - channel_auto_read(ic); - channel_abort(ic); - channel_auto_close(ic); - channel_erase(ic); - channel_truncate(oc); - - if (likely(msg && msg->data)) - co_inject(oc, msg->area, msg->data); - - oc->wex = tick_add_ifset(now_ms, oc->wto); - channel_auto_read(oc); - channel_auto_close(oc); - channel_shutr_now(oc); -} - /* * This function performs a shutdown-read on a detached stream interface in a * connected or init state (it does nothing for other states). It either shuts