Skip to content

Commit bd93fec

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

5 files changed

+14
-37
lines changed

src/ngx_stream_lua_socket_tcp.c

+1-14
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,8 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
276276
/* }}} */
277277

278278
/* {{{tcp object metatable */
279-
<<<<<<< HEAD
280-
lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key);
279+
lua_pushlightuserdata(L, &ngx_stream_lua_socket_tcp_metatable_key);
281280
lua_createtable(L, 0 /* narr */, 11 /* nrec */);
282-
=======
283-
lua_pushlightuserdata(L, &ngx_stream_lua_skcoet_tcp_metatable_key);
284-
lua_createtable(L, 0 /* narr */, 12 /* nrec */);
285-
286-
lua_pushcfunction(L, ngx_stream_lua_socket_tcp_bind);
287-
lua_setfield(L, -2, "bind");
288-
>>>>>>> 75a9f4b... udp downstream api - work in progress
289281

290282
lua_pushcfunction(L, ngx_stream_lua_socket_tcp_connect);
291283
lua_setfield(L, -2, "connect");
@@ -396,13 +388,8 @@ ngx_stream_lua_socket_tcp(lua_State *L)
396388
ngx_stream_lua_check_context(L, ctx, NGX_STREAM_LUA_CONTEXT_CONTENT
397389
| NGX_STREAM_LUA_CONTEXT_TIMER);
398390

399-
<<<<<<< HEAD
400391
lua_createtable(L, 3 /* narr */, 1 /* nrec */);
401-
lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key);
402-
=======
403-
lua_createtable(L, 4 /* narr */, 1 /* nrec */);
404392
lua_pushlightuserdata(L, &ngx_stream_lua_socket_tcp_metatable_key);
405-
>>>>>>> 75a9f4b... udp downstream api - work in progress
406393
lua_rawget(L, LUA_REGISTRYINDEX);
407394
lua_setmetatable(L, -2);
408395

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

src/ngx_stream_lua_socket_udp.h

-11
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ struct ngx_stream_lua_socket_udp_upstream_s {
4646

4747
ngx_stream_lua_resolved_t *resolved;
4848

49-
<<<<<<< HEAD
50-
ngx_uint_t ft_type;
51-
ngx_err_t socket_errno;
52-
size_t received; /* for receive */
53-
size_t recv_buf_size;
54-
55-
ngx_stream_lua_co_ctx_t *co_ctx;
56-
57-
unsigned waiting; /* :1 */
58-
=======
5949
ngx_uint_t ft_type;
6050
ngx_err_t socket_errno;
6151
size_t received; /* for receive */
@@ -65,7 +55,6 @@ struct ngx_stream_lua_socket_udp_upstream_s {
6555
unsigned raw_downstream:1;
6656
unsigned waiting:1;
6757
unsigned connected:1;
68-
>>>>>>> 75a9f4b... udp downstream api - work in progress
6958
};
7059

7160

t/065-tcp-socket-timeout.t

-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ lua tcp socket connect timed out
138138
--- timeout: 10
139139

140140

141-
142141
=== TEST 5: sock:settimeout(-1) does not override lua_socket_connect_timeout
143142
--- stream_server_config
144143
lua_socket_connect_timeout 102ms;

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)