Skip to content

Commit

Permalink
adopt changes from agentzh bloody-dns-server
Browse files Browse the repository at this point in the history
  • Loading branch information
alonbg committed Nov 1, 2016
1 parent 2171768 commit bd93fec
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 37 deletions.
15 changes: 1 addition & 14 deletions src/ngx_stream_lua_socket_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand Down
20 changes: 11 additions & 9 deletions src/ngx_stream_lua_socket_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 0 additions & 11 deletions src/ngx_stream_lua_socket_udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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
};


Expand Down
1 change: 0 additions & 1 deletion t/065-tcp-socket-timeout.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions t/138-req-udp-socket.t
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down

0 comments on commit bd93fec

Please sign in to comment.