Skip to content

Commit b392061

Browse files
author
alonbg
committed
adopt changes from agentzh bloody-dns-server
1 parent f28a4d7 commit b392061

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
@@ -1096,8 +1096,8 @@ ngx_stream_lua_socket_udp_receive(lua_State *L)
10961096
ngx_stream_lua_srv_conf_t *lscf;
10971097

10981098
nargs = lua_gettop(L);
1099-
if (nargs != 1) {
1100-
return luaL_error(L, "expecting 1 arguments "
1099+
if (nargs != 1 && nargs != 2) {
1100+
return luaL_error(L, "expecting 1 or 2 arguments "
11011101
"(including the object), but got %d", nargs);
11021102
}
11031103

@@ -1161,14 +1161,15 @@ ngx_stream_lua_socket_udp_receive(lua_State *L)
11611161

11621162
if (u->raw_downstream && !u->connected) {
11631163
u->received = c->buffer->last - c->buffer->pos;
1164-
c->buffer->pos = ngx_copy(ngx_stream_lua_socket_udp_buffer,
1165-
c->buffer->pos, u->received);
1166-
ngx_stream_lua_socket_udp_handle_success(s, u);
1167-
u->connected = 1;
1168-
rc = NGX_OK;
1164+
c->buffer->pos =
1165+
ngx_copy(ngx_stream_lua_socket_udp_buffer, c->buffer->pos,
1166+
u->received);
1167+
ngx_stream_lua_socket_udp_handle_success(s, u);
1168+
u->connected = 1;
1169+
rc = NGX_OK;
11691170

11701171
} else {
1171-
rc = ngx_stream_lua_socket_udp_read(s, u);
1172+
rc = ngx_stream_lua_socket_udp_read(s, u);
11721173
}
11731174

11741175
if (rc == NGX_ERROR) {
@@ -1507,8 +1508,9 @@ ngx_stream_lua_socket_udp_handler(ngx_event_t *ev)
15071508
c = ev->data;
15081509
u = c->data;
15091510
s = u->session;
1511+
c = s->connection;
15101512

1511-
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0,
1513+
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0,
15121514
"stream lua udp socket handler, wev %d", (int) ev->write);
15131515

15141516
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)