]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: minor cleanup in hlua_socket_new()
authorWilly Tarreau <w@1wt.eu>
Sun, 5 Apr 2015 22:48:33 +0000 (00:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 6 Apr 2015 09:37:36 +0000 (11:37 +0200)
Just limit the number of dereferences of socket-> since we allocate
the stream at the beginning.

src/hlua.c

index 224d2d5f623577f1b1475c79498192b098ef6ff2..076da63e0e7eff51529a2523727f91e217761e70 100644 (file)
@@ -1999,6 +1999,7 @@ __LJMP static int hlua_socket_new(lua_State *L)
        struct hlua_socket *socket;
        struct appctx *appctx;
        struct session *sess;
+       struct stream *strm;
        struct task *task;
 
        /* Check stack size. */
@@ -2025,8 +2026,10 @@ __LJMP static int hlua_socket_new(lua_State *L)
 
        /* Create the applet context */
        appctx = appctx_new(&update_applet);
-       if (!appctx)
+       if (!appctx) {
+               hlua_pusherror(L, "socket: out of memory");
                goto out_fail_conf;
+       }
 
        appctx->ctx.hlua.socket = socket;
        appctx->ctx.hlua.connected = 0;
@@ -2040,41 +2043,44 @@ __LJMP static int hlua_socket_new(lua_State *L)
                goto out_fail_sess;
        }
 
-       if ((task = task_new()) == NULL) {
+       task = task_new();
+       if (!task) {
                hlua_pusherror(L, "socket: out of memory");
                goto out_fail_task;
        }
        task->nice = 0;
 
-       if ((socket->s = stream_new(sess, task)) == NULL) {
+       strm = stream_new(sess, task);
+       if (!strm) {
                hlua_pusherror(L, "socket: out of memory");
                goto out_fail_stream;
        }
 
        /* Configure an empty Lua for the stream. */
-       socket->s->hlua.T = NULL;
-       socket->s->hlua.Tref = LUA_REFNIL;
-       socket->s->hlua.Mref = LUA_REFNIL;
-       socket->s->hlua.nargs = 0;
-       socket->s->hlua.flags = 0;
-       LIST_INIT(&socket->s->hlua.com);
+       socket->s = strm;
+       strm->hlua.T = NULL;
+       strm->hlua.Tref = LUA_REFNIL;
+       strm->hlua.Mref = LUA_REFNIL;
+       strm->hlua.nargs = 0;
+       strm->hlua.flags = 0;
+       LIST_INIT(&strm->hlua.com);
 
        /* Adjust the stream's timeouts */
-       socket->s->req.rto = socket_proxy.timeout.client;
-       socket->s->req.wto = socket_proxy.timeout.server;
-       socket->s->res.rto = socket_proxy.timeout.server;
-       socket->s->res.wto = socket_proxy.timeout.client;
+       strm->req.rto = socket_proxy.timeout.client;
+       strm->req.wto = socket_proxy.timeout.server;
+       strm->res.rto = socket_proxy.timeout.server;
+       strm->res.wto = socket_proxy.timeout.client;
 
        /* Configure "right" stream interface. this "si" is used to connect
         * and retrieve data from the server. The connection is initialized
         * with the "struct server".
         */
-       si_set_state(&socket->s->si[1], SI_ST_ASS);
-       socket->s->si[1].conn_retries = socket_proxy.conn_retries;
+       si_set_state(&strm->si[1], SI_ST_ASS);
+       strm->si[1].conn_retries = socket_proxy.conn_retries;
 
        /* Force destination server. */
-       socket->s->flags |= SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET | SF_BE_ASSIGNED;
-       socket->s->target = &socket_tcp.obj_type;
+       strm->flags |= SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET | SF_BE_ASSIGNED;
+       strm->target = &socket_tcp.obj_type;
 
        /* Update statistics counters. */
        socket_proxy.feconn++; /* beconn will be increased later */