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 Sep 18, 2016
1 parent a440866 commit 75a9f4b
Show file tree
Hide file tree
Showing 11 changed files with 858 additions and 35 deletions.
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 @@ -96,7 +96,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 @@ -197,7 +197,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 @@ -293,7 +293,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_skcoet_tcp_metatable_key);
lua_createtable(L, 0 /* narr */, 12 /* nrec */);

lua_pushcfunction(L, ngx_stream_lua_socket_tcp_bind);
Expand Down Expand Up @@ -384,14 +384,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 @@ -417,7 +409,7 @@ ngx_stream_lua_socket_tcp(lua_State *L)
| NGX_STREAM_LUA_CONTEXT_TIMER);

lua_createtable(L, 4 /* 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 @@ -4047,14 +4039,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 @@ -4085,6 +4085,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 @@ -150,7 +150,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 75a9f4b

Please sign in to comment.