]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream-int/stream: Move si_retnclose() in the stream scope
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 31 Mar 2022 07:47:24 +0000 (09:47 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 13 Apr 2022 13:10:15 +0000 (15:10 +0200)
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.

include/haproxy/stream.h
include/haproxy/stream_interface.h
src/cli.c
src/stream.c
src/stream_interface.c

index 6cf8d14e603267083c7adda3728b55bd182740d3..32070178a57508f7e06099dbb56df1b4ccd7eecf 100644 (file)
@@ -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);
index 9747d2ce4f490cdef1dad0059de5678214e8121f..0085de8efc4a4d030ed63454068511b445e22a48 100644 (file)
@@ -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);
index 5ed96f54075eae24026c67d4e334f49305d5d9c2..baea805e167bb55334c599963af67091f3d650d0 100644 (file)
--- 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)
index d8651253569226d8bcdda2a409215f41b5c10330..ec6e1f620c177dc5d30171b6f30b1b7c0dc1e134 100644 (file)
@@ -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) {
index 9bcfb2c8a9bdbd7eb66a688119274ea637381c14..ca7c616ec97fafc450ce3b5ca1ffa4ad83c478ed 100644 (file)
@@ -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