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.
This commit is contained in:
Christopher Faulet 2022-03-31 09:47:24 +02:00
parent 62e757470a
commit 9125f3cc77
5 changed files with 31 additions and 33 deletions

View 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);

View 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);

View File

@ -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)

View 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) {

View 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