Skip to content

Commit d60c2fb

Browse files
author
alonbg
committed
adopt changes from agentzh bloody-dns-server
1 parent 75a9f4b commit d60c2fb

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/ngx_stream_lua_socket_udp.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,8 @@ ngx_stream_lua_socket_udp_receive(lua_State *L)
11771177
ngx_stream_lua_srv_conf_t *lscf;
11781178

11791179
nargs = lua_gettop(L);
1180-
if (nargs != 1) {
1181-
return luaL_error(L, "expecting 1 arguments "
1180+
if (nargs != 1 && nargs != 2) {
1181+
return luaL_error(L, "expecting 1 or 2 arguments "
11821182
"(including the object), but got %d", nargs);
11831183
}
11841184

@@ -1242,14 +1242,15 @@ ngx_stream_lua_socket_udp_receive(lua_State *L)
12421242

12431243
if (u->raw_downstream && !u->connected) {
12441244
u->received = c->buffer->last - c->buffer->pos;
1245-
c->buffer->pos = ngx_copy(ngx_stream_lua_socket_udp_buffer,
1246-
c->buffer->pos, u->received);
1247-
ngx_stream_lua_socket_udp_handle_success(s, u);
1248-
u->connected = 1;
1249-
rc = NGX_OK;
1245+
c->buffer->pos =
1246+
ngx_copy(ngx_stream_lua_socket_udp_buffer, c->buffer->pos,
1247+
u->received);
1248+
ngx_stream_lua_socket_udp_handle_success(s, u);
1249+
u->connected = 1;
1250+
rc = NGX_OK;
12501251

12511252
} else {
1252-
rc = ngx_stream_lua_socket_udp_read(s, u);
1253+
rc = ngx_stream_lua_socket_udp_read(s, u);
12531254
}
12541255

12551256
if (rc == NGX_ERROR) {
@@ -1588,8 +1589,9 @@ ngx_stream_lua_socket_udp_handler(ngx_event_t *ev)
15881589
c = ev->data;
15891590
u = c->data;
15901591
s = u->session;
1592+
c = s->connection;
15911593

1592-
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0,
1594+
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0,
15931595
"stream lua udp socket handler, wev %d", (int) ev->write);
15941596

15951597
u->read_event_handler(s, u);

t/138-req-udp-socket.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ not supported in udp requests
121121
content_by_lua_block {
122122
local sock, err = ngx.req.udp_socket()
123123
sock:send("")
124-
sock:receive(5)
124+
sock:receive(5,4)
125125
}
126126

127127
--- dgram_response
128128
--- error_log
129-
expecting 1 arguments (including the object), but got 2
129+
expecting 1 or 2 arguments (including the object), but got 3
130130

131131

132132

0 commit comments

Comments
 (0)