Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downstream UDP support #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ngx_stream_lua_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ ngx_stream_lua_ngx_echo(lua_State *L, unsigned newline)
return luaL_error(L, "no session object found");
}

if (s->connection->type == SOCK_DGRAM) {
return luaL_error(L, "not supported in udp requests");
}

ctx = ngx_stream_get_module_ctx(s, ngx_stream_lua_module);

if (ctx == NULL) {
Expand Down Expand Up @@ -476,6 +480,10 @@ ngx_stream_lua_ngx_flush(lua_State *L)

s = ngx_stream_lua_get_session(L);

if (s->connection->type == SOCK_DGRAM) {
return luaL_error(L, "not supported in udp requests");
}

wait = 1; /* always wait */

ctx = ngx_stream_get_module_ctx(s, ngx_stream_lua_module);
Expand Down Expand Up @@ -563,6 +571,10 @@ ngx_stream_lua_ngx_eof(lua_State *L)
return luaL_error(L, "no session object found");
}

if (s->connection->type == SOCK_DGRAM) {
return luaL_error(L, "not supported in udp requests");
}

if (lua_gettop(L) != 0) {
return luaL_error(L, "no argument is expected");
}
Expand Down
33 changes: 19 additions & 14 deletions src/ngx_stream_lua_socket_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static int ngx_stream_lua_socket_receiveuntil_iterator(lua_State *L);
static ngx_int_t ngx_stream_lua_socket_compile_pattern(u_char *data, size_t len,
ngx_stream_lua_socket_compiled_pattern_t *cp, ngx_log_t *log);
static int ngx_stream_lua_socket_cleanup_compiled_pattern(lua_State *L);
static int ngx_stream_lua_req_socket(lua_State *L);
static int ngx_stream_lua_tcp_req_socket(lua_State *L);
static void ngx_stream_lua_req_socket_rev_handler(ngx_stream_session_t *s,
ngx_stream_lua_ctx_t *ctx);
static int ngx_stream_lua_socket_tcp_getreusedtimes(lua_State *L);
Expand Down Expand Up @@ -193,7 +193,7 @@ enum {
static char ngx_stream_lua_req_socket_metatable_key;
#endif
static char ngx_stream_lua_raw_req_socket_metatable_key;
static char ngx_stream_lua_tcp_socket_metatable_key;
static char ngx_stream_lua_socket_tcp_metatable_key;
static char ngx_stream_lua_upstream_udata_metatable_key;
static char ngx_stream_lua_downstream_udata_metatable_key;
static char ngx_stream_lua_pool_udata_metatable_key;
Expand Down Expand Up @@ -276,7 +276,7 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
/* }}} */

/* {{{tcp object metatable */
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_pushcfunction(L, ngx_stream_lua_socket_tcp_connect);
Expand Down Expand Up @@ -364,14 +364,6 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
}


void
ngx_stream_lua_inject_req_socket_api(lua_State *L)
{
lua_pushcfunction(L, ngx_stream_lua_req_socket);
lua_setfield(L, -2, "socket");
}


static int
ngx_stream_lua_socket_tcp(lua_State *L)
{
Expand All @@ -397,7 +389,7 @@ ngx_stream_lua_socket_tcp(lua_State *L)
| NGX_STREAM_LUA_CONTEXT_TIMER);

lua_createtable(L, 3 /* narr */, 1 /* nrec */);
lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key);
lua_pushlightuserdata(L, &ngx_stream_lua_socket_tcp_metatable_key);
lua_rawget(L, LUA_REGISTRYINDEX);
lua_setmetatable(L, -2);

Expand Down Expand Up @@ -3918,14 +3910,22 @@ ngx_stream_lua_socket_cleanup_compiled_pattern(lua_State *L)
}


void
ngx_stream_lua_inject_tcp_req_socket_api(lua_State *L)
{
lua_pushcfunction(L, ngx_stream_lua_tcp_req_socket);
lua_setfield(L, -2, "socket");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better keep this function in the same place (before ngx_stream_lua_socket_tcp) that will have a better diff :)



static int
ngx_stream_lua_req_socket(lua_State *L)
ngx_stream_lua_tcp_req_socket(lua_State *L)
{
int n, raw;
ngx_stream_session_t *s;
ngx_peer_connection_t *pc;
ngx_stream_lua_srv_conf_t *lscf;
ngx_connection_t *c;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

ngx_stream_session_t *s;
ngx_stream_lua_ctx_t *ctx;
ngx_stream_lua_co_ctx_t *coctx;
ngx_stream_lua_cleanup_t *cln;
Expand Down Expand Up @@ -3956,6 +3956,11 @@ ngx_stream_lua_req_socket(lua_State *L)

c = s->connection;

if (c->type != SOCK_STREAM) {
return luaL_error(L, "socket api does not match connection transport",
lua_gettop(L));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better remove lua_gettop here?

}

#if !defined(nginx_version) || nginx_version < 1003013
lua_pushnil(L);
lua_pushliteral(L, "nginx version too old");
Expand Down
2 changes: 1 addition & 1 deletion src/ngx_stream_lua_socket_tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ typedef struct {


void ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L);
void ngx_stream_lua_inject_req_socket_api(lua_State *L);
void ngx_stream_lua_inject_tcp_req_socket_api(lua_State *L);
void ngx_stream_lua_cleanup_conn_pools(lua_State *L);


Expand Down
Loading