Skip to content

Commit acd5242

Browse files
Alon Blayer-Gatalonbg
Alon Blayer-Gat
authored and
alonbg
committed
udp downstream api - work in progress
Conflicts: src/ngx_stream_lua_socket_tcp.c src/ngx_stream_lua_socket_udp.h
1 parent aafd50b commit acd5242

12 files changed

+857
-34
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
@@ -95,7 +95,7 @@ static int ngx_stream_lua_socket_receiveuntil_iterator(lua_State *L);
9595
static ngx_int_t ngx_stream_lua_socket_compile_pattern(u_char *data, size_t len,
9696
ngx_stream_lua_socket_compiled_pattern_t *cp, ngx_log_t *log);
9797
static int ngx_stream_lua_socket_cleanup_compiled_pattern(lua_State *L);
98-
static int ngx_stream_lua_req_socket(lua_State *L);
98+
static int ngx_stream_lua_tcp_req_socket(lua_State *L);
9999
static void ngx_stream_lua_req_socket_rev_handler(ngx_stream_session_t *s,
100100
ngx_stream_lua_ctx_t *ctx);
101101
static int ngx_stream_lua_socket_tcp_getreusedtimes(lua_State *L);
@@ -193,7 +193,7 @@ enum {
193193
static char ngx_stream_lua_req_socket_metatable_key;
194194
#endif
195195
static char ngx_stream_lua_raw_req_socket_metatable_key;
196-
static char ngx_stream_lua_tcp_socket_metatable_key;
196+
static char ngx_stream_lua_socket_tcp_metatable_key;
197197
static char ngx_stream_lua_upstream_udata_metatable_key;
198198
static char ngx_stream_lua_downstream_udata_metatable_key;
199199
static char ngx_stream_lua_pool_udata_metatable_key;
@@ -276,7 +276,7 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
276276
/* }}} */
277277

278278
/* {{{tcp object metatable */
279-
lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key);
279+
lua_pushlightuserdata(L, &ngx_stream_lua_socket_tcp_metatable_key);
280280
lua_createtable(L, 0 /* narr */, 11 /* nrec */);
281281

282282
lua_pushcfunction(L, ngx_stream_lua_socket_tcp_connect);
@@ -364,14 +364,6 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
364364
}
365365

366366

367-
void
368-
ngx_stream_lua_inject_req_socket_api(lua_State *L)
369-
{
370-
lua_pushcfunction(L, ngx_stream_lua_req_socket);
371-
lua_setfield(L, -2, "socket");
372-
}
373-
374-
375367
static int
376368
ngx_stream_lua_socket_tcp(lua_State *L)
377369
{
@@ -397,7 +389,7 @@ ngx_stream_lua_socket_tcp(lua_State *L)
397389
| NGX_STREAM_LUA_CONTEXT_TIMER);
398390

399391
lua_createtable(L, 3 /* narr */, 1 /* nrec */);
400-
lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key);
392+
lua_pushlightuserdata(L, &ngx_stream_lua_socket_tcp_metatable_key);
401393
lua_rawget(L, LUA_REGISTRYINDEX);
402394
lua_setmetatable(L, -2);
403395

@@ -3918,14 +3910,22 @@ ngx_stream_lua_socket_cleanup_compiled_pattern(lua_State *L)
39183910
}
39193911

39203912

3913+
void
3914+
ngx_stream_lua_inject_tcp_req_socket_api(lua_State *L)
3915+
{
3916+
lua_pushcfunction(L, ngx_stream_lua_tcp_req_socket);
3917+
lua_setfield(L, -2, "socket");
3918+
}
3919+
3920+
39213921
static int
3922-
ngx_stream_lua_req_socket(lua_State *L)
3922+
ngx_stream_lua_tcp_req_socket(lua_State *L)
39233923
{
39243924
int n, raw;
3925+
ngx_stream_session_t *s;
39253926
ngx_peer_connection_t *pc;
39263927
ngx_stream_lua_srv_conf_t *lscf;
39273928
ngx_connection_t *c;
3928-
ngx_stream_session_t *s;
39293929
ngx_stream_lua_ctx_t *ctx;
39303930
ngx_stream_lua_co_ctx_t *coctx;
39313931
ngx_stream_lua_cleanup_t *cln;
@@ -3956,6 +3956,11 @@ ngx_stream_lua_req_socket(lua_State *L)
39563956

39573957
c = s->connection;
39583958

3959+
if (c->type != SOCK_STREAM) {
3960+
return luaL_error(L, "socket api does not match connection transport",
3961+
lua_gettop(L));
3962+
}
3963+
39593964
#if !defined(nginx_version) || nginx_version < 1003013
39603965
lua_pushnil(L);
39613966
lua_pushliteral(L, "nginx version too old");

src/ngx_stream_lua_socket_tcp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ typedef struct {
147147

148148

149149
void ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L);
150-
void ngx_stream_lua_inject_req_socket_api(lua_State *L);
150+
void ngx_stream_lua_inject_tcp_req_socket_api(lua_State *L);
151151
void ngx_stream_lua_cleanup_conn_pools(lua_State *L);
152152

153153

0 commit comments

Comments
 (0)