From: Christopher Faulet Date: Wed, 23 May 2018 13:03:43 +0000 (+0200) Subject: MINOR: conn_stream: add cs_send() as a default snd_buf() function X-Git-Tag: v1.9-dev2~192 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=063f786553d97f53aefba3651d7d7ce22dde4952;p=thirdparty%2Fhaproxy.git MINOR: conn_stream: add cs_send() as a default snd_buf() function This function is generic and is able to automatically transfer data from a buffer to the conn_stream's tx buffer. It does this automatically if the mux doesn't define another snd_buf() function. It cannot yet be used as-is with the conn_stream's txbuf without risking to lose data on close since conn_streams need to be orphaned for this. --- diff --git a/include/proto/connection.h b/include/proto/connection.h index 2111f67d2f..580ae9a32d 100644 --- a/include/proto/connection.h +++ b/include/proto/connection.h @@ -46,6 +46,7 @@ void conn_fd_handler(int fd); /* conn_stream functions */ size_t __cs_recv(struct conn_stream *cs, struct buffer *buf, size_t count, int flags); +size_t __cs_send(struct conn_stream *cs, struct buffer *buf, size_t count, int flags); /* receive a PROXY protocol header over a connection */ int conn_recv_proxy(struct connection *conn, int flag); @@ -314,6 +315,17 @@ static inline size_t cs_recv(struct conn_stream *cs, struct buffer *buf, size_t return __cs_recv(cs, buf, count, flags); } +/* conn_stream send function. Uses mux->snd_buf() if defined, otherwise + * falls back to __cs_send(). + */ +static inline size_t cs_send(struct conn_stream *cs, struct buffer *buf, size_t count, int flags) +{ + if (cs->conn->mux->snd_buf) + return cs->conn->mux->snd_buf(cs, buf, count, flags); + else + return __cs_send(cs, buf, count, flags); +} + /***** Event manipulation primitives for use by DATA I/O callbacks *****/ /* The __conn_* versions do not propagate to lower layers and are only meant * to be used by handlers called by the connection handler. The other ones diff --git a/src/checks.c b/src/checks.c index 31a3939233..fc9c5679b7 100644 --- a/src/checks.c +++ b/src/checks.c @@ -771,7 +771,7 @@ static void __event_srv_chk_w(struct conn_stream *cs) goto out; if (b_data(&check->bo)) { - conn->mux->snd_buf(cs, &check->bo, b_data(&check->bo), 0); + cs_send(cs, &check->bo, b_data(&check->bo), 0); b_realign_if_empty(&check->bo); if (conn->flags & CO_FL_ERROR || cs->flags & CS_FL_ERROR) { chk_report_conn_err(check, errno, 0); @@ -2699,7 +2699,7 @@ static int tcpcheck_main(struct check *check) int ret; __cs_want_send(cs); - ret = conn->mux->snd_buf(cs, &check->bo, b_data(&check->bo), 0); + ret = cs_send(cs, &check->bo, b_data(&check->bo), 0); b_realign_if_empty(&check->bo); if (ret <= 0) { diff --git a/src/connection.c b/src/connection.c index 8826706f90..5d7f788ef6 100644 --- a/src/connection.c +++ b/src/connection.c @@ -410,6 +410,17 @@ size_t __cs_recv(struct conn_stream *cs, struct buffer *buf, size_t count, int f return ret; } +/* + * default cs send() : this one is used when mux->snd_buf == NULL. It puts up to + * bytes from into cs->txbuf. The number of bytes transferred is + * returned. Here we don't care if cs->txbuf is allocated or not. If not, it + * will be swapped with . + */ +size_t __cs_send(struct conn_stream *cs, struct buffer *buf, size_t count, int flags) +{ + return b_xfer(&cs->txbuf, buf, count); +} + /* * Get data length from tlv */ diff --git a/src/stream_interface.c b/src/stream_interface.c index 024c2f58c9..1d67c31b2e 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -721,7 +721,7 @@ static struct task * si_cs_send(struct task *t, void *ctx, unsigned short state) if (oc->flags & CF_STREAMER) send_flag |= CO_SFL_STREAMER; - ret = conn->mux->snd_buf(cs, &oc->buf, co_data(oc), send_flag); + ret = cs_send(cs, &oc->buf, co_data(oc), send_flag); if (ret > 0) { did_send = 1; oc->flags |= CF_WRITE_PARTIAL | CF_WROTE_DATA | CF_WRITE_EVENT;