MEDIUM: conn-stream: Pre-allocate endpoint to create CS from muxes and applets
It is a transient commit to prepare next changes. Now, when a conn-stream is
created from an applet or a multiplexer, an endpoint is always provided. In
addition, the API to create a conn-stream was specialized to have one
function per type.
The next step will be to share the endpoint structure.
diff --git a/src/hlua.c b/src/hlua.c
index 3f9b123..705c15c 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2918,8 +2918,9 @@
struct hlua_socket *socket;
struct appctx *appctx;
struct session *sess;
+ struct cs_endpoint *endp;
struct conn_stream *cs;
- struct stream *strm;
+ struct stream *s;
/* Check stack size. */
if (!lua_checkstack(L, 3)) {
@@ -2944,17 +2945,11 @@
lua_rawgeti(L, LUA_REGISTRYINDEX, class_socket_ref);
lua_setmetatable(L, -2);
- cs = cs_new(NULL);
- if (!cs) {
- hlua_pusherror(L, "socket: out of memory");
- goto out_fail_conf;
- }
-
/* Create the applet context */
- appctx = appctx_new(&update_applet, cs);
+ appctx = appctx_new(&update_applet);
if (!appctx) {
hlua_pusherror(L, "socket: out of memory");
- goto out_fail_cs;
+ goto out_fail_conf;
}
appctx->ctx.hlua_cosocket.connected = 0;
@@ -2969,13 +2964,21 @@
goto out_fail_appctx;
}
+ endp = cs_endpoint_new();
+ if (!endp)
+ goto out_fail_sess;
+ endp->target = appctx;
+ endp->ctx = appctx;
+ endp->flags |= CS_EP_T_APPLET;
+
- strm = stream_new(sess, cs, &BUF_NULL);
- if (!strm) {
+ cs = cs_new_from_applet(endp, sess, &BUF_NULL);
+ if (!cs) {
hlua_pusherror(L, "socket: out of memory");
+ cs_endpoint_free(endp);
goto out_fail_sess;
}
- cs_attach_endp_app(cs, appctx, appctx);
+ s = DISGUISE(cs_strm(cs));
/* Initialise cross reference between stream and Lua socket object. */
xref_create(&socket->xref, &appctx->ctx.hlua_cosocket.xref);
@@ -2984,11 +2987,11 @@
* and retrieve data from the server. The connection is initialized
* with the "struct server".
*/
- si_set_state(strm->csb->si, SI_ST_ASS);
+ si_set_state(cs_si(s->csb), SI_ST_ASS);
/* Force destination server. */
- strm->flags |= SF_DIRECT | SF_ASSIGNED | SF_BE_ASSIGNED;
- strm->target = &socket_tcp->obj_type;
+ s->flags |= SF_DIRECT | SF_ASSIGNED | SF_BE_ASSIGNED;
+ s->target = &socket_tcp->obj_type;
return 1;
@@ -2996,8 +2999,6 @@
session_free(sess);
out_fail_appctx:
appctx_free(appctx);
- out_fail_cs:
- cs_free(cs);
out_fail_conf:
WILL_LJMP(lua_error(L));
return 0;