From 1cf9ef25a9769ee653446aa0fad4ceaa55273167 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Fri, 25 Mar 2022 15:21:46 +0100 Subject: [PATCH] MINOR: conn-stream: Add header file with util functions related to conn-streams cs_utils.h header file will contain all util functions related to the conn_streams. For now, few functions were added, all are equivalent to SI functions. Idea is to progressively replace SI functions by CS ones. --- include/haproxy/cs_utils.h | 76 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 include/haproxy/cs_utils.h diff --git a/include/haproxy/cs_utils.h b/include/haproxy/cs_utils.h new file mode 100644 index 000000000..58334b8ce --- /dev/null +++ b/include/haproxy/cs_utils.h @@ -0,0 +1,76 @@ +/* + * include/haproxy/cs_utils.h + * This file contains conn-stream util functions prototypes + * + * Copyright 2022 Christopher Faulet + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, version 2.1 + * exclusively. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _HAPROXY_CS_UTILS_H +#define _HAPROXY_CS_UTILS_H + +#include +#include +#include +#include +#include +#include + +/* returns the channel which receives data from this conn-stream (input channel) */ +static inline struct channel *cs_ic(struct conn_stream *cs) +{ + struct stream *strm = __cs_strm(cs); + + return ((cs->flags & CS_FL_ISBACK) ? &(strm->res) : &(strm->req)); +} + +/* returns the channel which feeds data to this conn-stream (output channel) */ +static inline struct channel *cs_oc(struct conn_stream *cs) +{ + struct stream *strm = __cs_strm(cs); + + return ((cs->flags & CS_FL_ISBACK) ? &(strm->req) : &(strm->res)); +} + +/* returns the buffer which receives data from this conn-stream (input channel's buffer) */ +static inline struct buffer *cs_ib(struct conn_stream *cs) +{ + return &cs_ic(cs)->buf; +} + +/* returns the buffer which feeds data to this conn-stream (output channel's buffer) */ +static inline struct buffer *cs_ob(struct conn_stream *cs) +{ + return &cs_oc(cs)->buf; +} +/* returns the stream's task associated to this conn-stream */ +static inline struct task *cs_strm_task(struct conn_stream *cs) +{ + struct stream *strm = __cs_strm(cs); + + return strm->task; +} + +/* returns the conn-stream on the other side. Used during forwarding. */ +static inline struct conn_stream *cs_opposite(struct conn_stream *cs) +{ + struct stream *strm = __cs_strm(cs); + + return ((cs->flags & CS_FL_ISBACK) ? strm->csf : strm->csb); +} + + +#endif /* _HAPROXY_CS_UTILS_H */