Skip to content

Commit 75a9f4b

Browse files
Alon Blayer-Gatalonbg
Alon Blayer-Gat
authored and
alonbg
committed
udp downstream api - work in progress
1 parent a440866 commit 75a9f4b

11 files changed

+858
-35
lines changed

src/ngx_stream_lua_output.c

+12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ ngx_stream_lua_ngx_echo(lua_State *L, unsigned newline)
6060
return luaL_error(L, "no session object found");
6161
}
6262

63+
if (s->connection->type == SOCK_DGRAM) {
64+
return luaL_error(L, "not supported in udp requests");
65+
}
66+
6367
ctx = ngx_stream_get_module_ctx(s, ngx_stream_lua_module);
6468

6569
if (ctx == NULL) {
@@ -476,6 +480,10 @@ ngx_stream_lua_ngx_flush(lua_State *L)
476480

477481
s = ngx_stream_lua_get_session(L);
478482

483+
if (s->connection->type == SOCK_DGRAM) {
484+
return luaL_error(L, "not supported in udp requests");
485+
}
486+
479487
wait = 1; /* always wait */
480488

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

574+
if (s->connection->type == SOCK_DGRAM) {
575+
return luaL_error(L, "not supported in udp requests");
576+
}
577+
566578
if (lua_gettop(L) != 0) {
567579
return luaL_error(L, "no argument is expected");
568580
}

src/ngx_stream_lua_socket_tcp.c

+19-14
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int ngx_stream_lua_socket_receiveuntil_iterator(lua_State *L);
9696
static ngx_int_t ngx_stream_lua_socket_compile_pattern(u_char *data, size_t len,
9797
ngx_stream_lua_socket_compiled_pattern_t *cp, ngx_log_t *log);
9898
static int ngx_stream_lua_socket_cleanup_compiled_pattern(lua_State *L);
99-
static int ngx_stream_lua_req_socket(lua_State *L);
99+
static int ngx_stream_lua_tcp_req_socket(lua_State *L);
100100
static void ngx_stream_lua_req_socket_rev_handler(ngx_stream_session_t *s,
101101
ngx_stream_lua_ctx_t *ctx);
102102
static int ngx_stream_lua_socket_tcp_getreusedtimes(lua_State *L);
@@ -197,7 +197,7 @@ enum {
197197
static char ngx_stream_lua_req_socket_metatable_key;
198198
#endif
199199
static char ngx_stream_lua_raw_req_socket_metatable_key;
200-
static char ngx_stream_lua_tcp_socket_metatable_key;
200+
static char ngx_stream_lua_socket_tcp_metatable_key;
201201
static char ngx_stream_lua_upstream_udata_metatable_key;
202202
static char ngx_stream_lua_downstream_udata_metatable_key;
203203
static char ngx_stream_lua_pool_udata_metatable_key;
@@ -293,7 +293,7 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
293293
/* }}} */
294294

295295
/* {{{tcp object metatable */
296-
lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key);
296+
lua_pushlightuserdata(L, &ngx_stream_lua_skcoet_tcp_metatable_key);
297297
lua_createtable(L, 0 /* narr */, 12 /* nrec */);
298298

299299
lua_pushcfunction(L, ngx_stream_lua_socket_tcp_bind);
@@ -384,14 +384,6 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
384384
}
385385

386386

387-
void
388-
ngx_stream_lua_inject_req_socket_api(lua_State *L)
389-
{
390-
lua_pushcfunction(L, ngx_stream_lua_req_socket);
391-
lua_setfield(L, -2, "socket");
392-
}
393-
394-
395387
static int
396388
ngx_stream_lua_socket_tcp(lua_State *L)
397389
{
@@ -417,7 +409,7 @@ ngx_stream_lua_socket_tcp(lua_State *L)
417409
| NGX_STREAM_LUA_CONTEXT_TIMER);
418410

419411
lua_createtable(L, 4 /* narr */, 1 /* nrec */);
420-
lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key);
412+
lua_pushlightuserdata(L, &ngx_stream_lua_socket_tcp_metatable_key);
421413
lua_rawget(L, LUA_REGISTRYINDEX);
422414
lua_setmetatable(L, -2);
423415

@@ -4047,14 +4039,22 @@ ngx_stream_lua_socket_cleanup_compiled_pattern(lua_State *L)
40474039
}
40484040

40494041

4042+
void
4043+
ngx_stream_lua_inject_tcp_req_socket_api(lua_State *L)
4044+
{
4045+
lua_pushcfunction(L, ngx_stream_lua_tcp_req_socket);
4046+
lua_setfield(L, -2, "socket");
4047+
}
4048+
4049+
40504050
static int
4051-
ngx_stream_lua_req_socket(lua_State *L)
4051+
ngx_stream_lua_tcp_req_socket(lua_State *L)
40524052
{
40534053
int n, raw;
4054+
ngx_stream_session_t *s;
40544055
ngx_peer_connection_t *pc;
40554056
ngx_stream_lua_srv_conf_t *lscf;
40564057
ngx_connection_t *c;
4057-
ngx_stream_session_t *s;
40584058
ngx_stream_lua_ctx_t *ctx;
40594059
ngx_stream_lua_co_ctx_t *coctx;
40604060
ngx_stream_lua_cleanup_t *cln;
@@ -4085,6 +4085,11 @@ ngx_stream_lua_req_socket(lua_State *L)
40854085

40864086
c = s->connection;
40874087

4088+
if (c->type != SOCK_STREAM) {
4089+
return luaL_error(L, "socket api does not match connection transport",
4090+
lua_gettop(L));
4091+
}
4092+
40884093
#if !defined(nginx_version) || nginx_version < 1003013
40894094
lua_pushnil(L);
40904095
lua_pushliteral(L, "nginx version too old");

src/ngx_stream_lua_socket_tcp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ typedef struct {
150150

151151

152152
void ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L);
153-
void ngx_stream_lua_inject_req_socket_api(lua_State *L);
153+
void ngx_stream_lua_inject_tcp_req_socket_api(lua_State *L);
154154
void ngx_stream_lua_cleanup_conn_pools(lua_State *L);
155155

156156

0 commit comments

Comments
 (0)