From bd93fec405f249027b1ce36317a8a3b619ca1dcb 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_tcp.c | 15 +-------------- src/ngx_stream_lua_socket_udp.c | 20 +++++++++++--------- src/ngx_stream_lua_socket_udp.h | 11 ----------- t/065-tcp-socket-timeout.t | 1 - t/138-req-udp-socket.t | 4 ++-- 5 files changed, 14 insertions(+), 37 deletions(-) diff --git a/src/ngx_stream_lua_socket_tcp.c b/src/ngx_stream_lua_socket_tcp.c index c1f1a8f4..f46a1c68 100644 --- a/src/ngx_stream_lua_socket_tcp.c +++ b/src/ngx_stream_lua_socket_tcp.c @@ -276,16 +276,8 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L) /* }}} */ /* {{{tcp object metatable */ -<<<<<<< HEAD - lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key); + lua_pushlightuserdata(L, &ngx_stream_lua_socket_tcp_metatable_key); lua_createtable(L, 0 /* narr */, 11 /* nrec */); -======= - lua_pushlightuserdata(L, &ngx_stream_lua_skcoet_tcp_metatable_key); - lua_createtable(L, 0 /* narr */, 12 /* nrec */); - - lua_pushcfunction(L, ngx_stream_lua_socket_tcp_bind); - lua_setfield(L, -2, "bind"); ->>>>>>> 75a9f4b... udp downstream api - work in progress lua_pushcfunction(L, ngx_stream_lua_socket_tcp_connect); lua_setfield(L, -2, "connect"); @@ -396,13 +388,8 @@ ngx_stream_lua_socket_tcp(lua_State *L) ngx_stream_lua_check_context(L, ctx, NGX_STREAM_LUA_CONTEXT_CONTENT | NGX_STREAM_LUA_CONTEXT_TIMER); -<<<<<<< HEAD lua_createtable(L, 3 /* narr */, 1 /* nrec */); - lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key); -======= - lua_createtable(L, 4 /* narr */, 1 /* nrec */); lua_pushlightuserdata(L, &ngx_stream_lua_socket_tcp_metatable_key); ->>>>>>> 75a9f4b... udp downstream api - work in progress lua_rawget(L, LUA_REGISTRYINDEX); lua_setmetatable(L, -2); 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/src/ngx_stream_lua_socket_udp.h b/src/ngx_stream_lua_socket_udp.h index e40b5e4f..e7ca378c 100644 --- a/src/ngx_stream_lua_socket_udp.h +++ b/src/ngx_stream_lua_socket_udp.h @@ -46,16 +46,6 @@ struct ngx_stream_lua_socket_udp_upstream_s { ngx_stream_lua_resolved_t *resolved; -<<<<<<< HEAD - ngx_uint_t ft_type; - ngx_err_t socket_errno; - size_t received; /* for receive */ - size_t recv_buf_size; - - ngx_stream_lua_co_ctx_t *co_ctx; - - unsigned waiting; /* :1 */ -======= ngx_uint_t ft_type; ngx_err_t socket_errno; size_t received; /* for receive */ @@ -65,7 +55,6 @@ struct ngx_stream_lua_socket_udp_upstream_s { unsigned raw_downstream:1; unsigned waiting:1; unsigned connected:1; ->>>>>>> 75a9f4b... udp downstream api - work in progress }; diff --git a/t/065-tcp-socket-timeout.t b/t/065-tcp-socket-timeout.t index d11cd015..2b952253 100644 --- a/t/065-tcp-socket-timeout.t +++ b/t/065-tcp-socket-timeout.t @@ -138,7 +138,6 @@ lua tcp socket connect timed out --- timeout: 10 - === TEST 5: sock:settimeout(-1) does not override lua_socket_connect_timeout --- stream_server_config lua_socket_connect_timeout 102ms; 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