From b392061cb5384bdb065691e2a041dd35e444fa32 Mon Sep 17 00:00:00 2001 From: alonbg Date: Thu, 8 Sep 2016 15:18:57 +0300 Subject: [PATCH] adopt changes from agentzh bloody-dns-server --- src/ngx_stream_lua_socket_udp.c | 20 +++++++++++--------- t/138-req-udp-socket.t | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ngx_stream_lua_socket_udp.c b/src/ngx_stream_lua_socket_udp.c index 81a442de..dc39d766 100644 --- a/src/ngx_stream_lua_socket_udp.c +++ b/src/ngx_stream_lua_socket_udp.c @@ -1096,8 +1096,8 @@ ngx_stream_lua_socket_udp_receive(lua_State *L) ngx_stream_lua_srv_conf_t *lscf; nargs = lua_gettop(L); - if (nargs != 1) { - return luaL_error(L, "expecting 1 arguments " + if (nargs != 1 && nargs != 2) { + return luaL_error(L, "expecting 1 or 2 arguments " "(including the object), but got %d", nargs); } @@ -1161,14 +1161,15 @@ ngx_stream_lua_socket_udp_receive(lua_State *L) if (u->raw_downstream && !u->connected) { u->received = c->buffer->last - c->buffer->pos; - c->buffer->pos = ngx_copy(ngx_stream_lua_socket_udp_buffer, - c->buffer->pos, u->received); - ngx_stream_lua_socket_udp_handle_success(s, u); - u->connected = 1; - rc = NGX_OK; + c->buffer->pos = + ngx_copy(ngx_stream_lua_socket_udp_buffer, c->buffer->pos, + u->received); + ngx_stream_lua_socket_udp_handle_success(s, u); + u->connected = 1; + rc = NGX_OK; } else { - rc = ngx_stream_lua_socket_udp_read(s, u); + rc = ngx_stream_lua_socket_udp_read(s, u); } if (rc == NGX_ERROR) { @@ -1507,8 +1508,9 @@ ngx_stream_lua_socket_udp_handler(ngx_event_t *ev) c = ev->data; u = c->data; s = u->session; + c = s->connection; - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "stream lua udp socket handler, wev %d", (int) ev->write); u->read_event_handler(s, u); diff --git a/t/138-req-udp-socket.t b/t/138-req-udp-socket.t index a1cb9c1c..297a4126 100644 --- a/t/138-req-udp-socket.t +++ b/t/138-req-udp-socket.t @@ -121,12 +121,12 @@ not supported in udp requests content_by_lua_block { local sock, err = ngx.req.udp_socket() sock:send("") - sock:receive(5) + sock:receive(5,4) } --- dgram_response --- error_log -expecting 1 arguments (including the object), but got 2 +expecting 1 or 2 arguments (including the object), but got 3