]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: introduce conn_stream
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 13 Sep 2017 16:30:23 +0000 (18:30 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 17:03:23 +0000 (18:03 +0100)
This patch introduces a new struct conn_stream. It's the stream-side of
a multiplexed connection. A pool is created and destroyed on exit. For
now the conn_streams are not used at all.

include/proto/connection.h
include/proto/obj_type.h
include/types/connection.h
include/types/obj_type.h
src/connection.c
src/haproxy.c

index 8ba4fc632a40ad4da1b36f64d2c83b36e6ec0d08..800937247f1a47981a7dcac2091737b10b6c3ce1 100644 (file)
@@ -31,6 +31,7 @@
 #include <proto/obj_type.h>
 
 extern struct pool_head *pool2_connection;
+extern struct pool_head *pool2_connstream;
 extern struct xprt_ops *registered_xprt[XPRT_ENTRIES];
 extern struct alpn_mux_list alpn_mux_list;
 
@@ -552,6 +553,11 @@ static inline void conn_free(struct connection *conn)
        pool_free2(pool2_connection, conn);
 }
 
+/* Returns the conn from a cs. If cs is NULL, returns NULL */
+static inline struct connection *cs_conn(const struct conn_stream *cs)
+{
+       return cs ? cs->conn : NULL;
+}
 
 /* Retrieves the connection's source address */
 static inline void conn_get_from_addr(struct connection *conn)
index 60265b5e137906f9c095c0972a7a9d72fd241bdb..617464ce34a706961fb1ddcb99c59541f961a6eb 100644 (file)
@@ -119,6 +119,18 @@ static inline struct appctx *objt_appctx(enum obj_type *t)
        return __objt_appctx(t);
 }
 
+static inline struct conn_stream *__objt_cs(enum obj_type *t)
+{
+       return (container_of(t, struct conn_stream, obj_type));
+}
+
+static inline struct conn_stream *objt_cs(enum obj_type *t)
+{
+       if (!t || *t != OBJ_TYPE_CS)
+               return NULL;
+       return __objt_cs(t);
+}
+
 static inline struct connection *__objt_conn(enum obj_type *t)
 {
        return container_of(t, struct connection, obj_type);
@@ -152,6 +164,7 @@ static inline void *obj_base_ptr(enum obj_type *t)
        case OBJ_TYPE_APPLET:   return __objt_applet(t);
        case OBJ_TYPE_APPCTX:   return __objt_appctx(t);
        case OBJ_TYPE_CONN:     return __objt_conn(t);
+       case OBJ_TYPE_CS:       return __objt_cs(t);
        default:                return NULL;
        }
 }
index b925f65ff6cf05123d9ca2b6960a79824d225ed1..9561406eb19afb6d955ae4b50a81305ed44c4918 100644 (file)
@@ -39,6 +39,7 @@
 
 /* referenced below */
 struct connection;
+struct conn_stream;
 struct buffer;
 struct server;
 struct pipe;
@@ -51,6 +52,15 @@ union conn_handle {
        int fd;                 /* file descriptor, for regular sockets */
 };
 
+/* conn_stream flags */
+enum {
+       CS_FL_NONE          = 0x00000000,  /* Just for initialization purposes */
+       CS_FL_DATA_RD_ENA   = 0x00000001,  /* receiving data is allowed */
+       CS_FL_DATA_WR_ENA   = 0x00000002,  /* sending data is desired */
+
+       CS_FL_ERROR         = 0x00000100,  /* a fatal error was reported */
+       CS_FL_EOS           = 0x00001000,  /* End of stream */
+};
 
 /* For each direction, we have a CO_FL_{SOCK,DATA}_<DIR>_ENA flag, which
  * indicates if read or write is desired in that direction for the respective
@@ -297,6 +307,18 @@ struct conn_src {
 #endif
 };
 
+/*
+ * This structure describes the elements of a connection relevant to a stream
+ */
+struct conn_stream {
+       enum obj_type obj_type;              /* differentiates connection from applet context */
+       struct connection *conn;             /* xprt-level connection */
+       unsigned int flags;                    /* CS_FL_* */
+       void *data;                          /* pointer to upper layer's entity (eg: stream interface) */
+       const struct data_cb *data_cb;       /* data layer callbacks. Must be set before xprt->init() */
+       void *ctx;                           /* mux-specific context */
+};
+
 /* This structure describes a connection with its methods and data.
  * A connection may be performed to proxy or server via a local or remote
  * socket, and can also be made to an internal applet. It can support
index a6310cfc0dc4b45b6a6e37988409b081227e86f1..e141d69e554b4a6d8baab68f6569caba9f062d4e 100644 (file)
@@ -40,6 +40,7 @@ enum obj_type {
        OBJ_TYPE_APPCTX,       /* object is a struct appctx */
        OBJ_TYPE_CONN,         /* object is a struct connection */
        OBJ_TYPE_SRVRQ,        /* object is a struct dns_srvrq */
+       OBJ_TYPE_CS,           /* object is a struct conn_stream */
        OBJ_TYPE_ENTRIES       /* last one : number of entries */
 } __attribute__((packed)) ;
 
index b61a9dd847a7db9d40628b2e363145e3f24b94ae..2e081d8ac9a417d96331db43a6cd021669d20896 100644 (file)
@@ -28,6 +28,7 @@
 #endif
 
 struct pool_head *pool2_connection;
+struct pool_head *pool2_connstream;
 struct xprt_ops *registered_xprt[XPRT_ENTRIES] = { NULL, };
 
 /* List head of all known muxes for ALPN */
@@ -39,7 +40,19 @@ struct alpn_mux_list alpn_mux_list = {
 int init_connection()
 {
        pool2_connection = create_pool("connection", sizeof (struct connection), MEM_F_SHARED);
-       return pool2_connection != NULL;
+       if (!pool2_connection)
+               goto fail_conn;
+
+       pool2_connstream = create_pool("conn_stream", sizeof(struct conn_stream), MEM_F_SHARED);
+       if (!pool2_connstream)
+               goto fail_cs;
+
+       return 1;
+ fail_cs:
+       pool_destroy2(pool2_connection);
+       pool2_connection = NULL;
+ fail_conn:
+       return 0;
 }
 
 /* I/O callback for fd-based connections. It calls the read/write handlers
index ed6c8ba8dfe374e007a5c0c8a16f09540fd1c9e8..d3db264ee5a10a99c267fb381daf305bf9869327 100644 (file)
@@ -2189,6 +2189,7 @@ void deinit(void)
        pool_destroy2(pool2_stream);
        pool_destroy2(pool2_session);
        pool_destroy2(pool2_connection);
+       pool_destroy2(pool2_connstream);
        pool_destroy2(pool2_requri);
        pool_destroy2(pool2_task);
        pool_destroy2(pool2_capture);