MINOR: connection: introduce conn_stream
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.
diff --git a/include/proto/connection.h b/include/proto/connection.h
index 8ba4fc6..8009372 100644
--- a/include/proto/connection.h
+++ b/include/proto/connection.h
@@ -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 @@
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)
diff --git a/include/proto/obj_type.h b/include/proto/obj_type.h
index 60265b5..617464c 100644
--- a/include/proto/obj_type.h
+++ b/include/proto/obj_type.h
@@ -119,6 +119,18 @@
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 @@
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;
}
}
diff --git a/include/types/connection.h b/include/types/connection.h
index b925f65..9561406 100644
--- a/include/types/connection.h
+++ b/include/types/connection.h
@@ -39,6 +39,7 @@
/* referenced below */
struct connection;
+struct conn_stream;
struct buffer;
struct server;
struct pipe;
@@ -51,6 +52,15 @@
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 @@
#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
diff --git a/include/types/obj_type.h b/include/types/obj_type.h
index a6310cf..e141d69 100644
--- a/include/types/obj_type.h
+++ b/include/types/obj_type.h
@@ -40,6 +40,7 @@
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)) ;
diff --git a/src/connection.c b/src/connection.c
index b61a9dd..2e081d8 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -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 @@
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
diff --git a/src/haproxy.c b/src/haproxy.c
index ed6c8ba..d3db264 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2189,6 +2189,7 @@
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);