Skip to content

Commit

Permalink
udp downstream api - work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Alon Blayer-Gat authored and alonbg committed Aug 22, 2016
1 parent 282c93c commit 92d3b01
Show file tree
Hide file tree
Showing 11 changed files with 857 additions and 34 deletions.
4 changes: 4 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, "api call is not supported under udp transport");
}

ctx = ngx_stream_get_module_ctx(s, ngx_stream_lua_module);

if (ctx == NULL) {
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 @@ -3919,14 +3911,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");
}


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;
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 @@ -3957,6 +3957,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));
}

#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

0 comments on commit 92d3b01

Please sign in to comment.