Skip to content

Commit 2171768

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 2171768

11 files changed

+872
-26
lines changed

src/ngx_stream_lua_output.c

Lines changed: 12 additions & 0 deletions
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

Lines changed: 30 additions & 12 deletions
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,8 +276,16 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
276276
/* }}} */
277277

278278
/* {{{tcp object metatable */
279+
<<<<<<< HEAD
279280
lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key);
280281
lua_createtable(L, 0 /* narr */, 11 /* nrec */);
282+
=======
283+
lua_pushlightuserdata(L, &ngx_stream_lua_skcoet_tcp_metatable_key);
284+
lua_createtable(L, 0 /* narr */, 12 /* nrec */);
285+
286+
lua_pushcfunction(L, ngx_stream_lua_socket_tcp_bind);
287+
lua_setfield(L, -2, "bind");
288+
>>>>>>> 75a9f4b... udp downstream api - work in progress
281289

282290
lua_pushcfunction(L, ngx_stream_lua_socket_tcp_connect);
283291
lua_setfield(L, -2, "connect");
@@ -364,14 +372,6 @@ ngx_stream_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
364372
}
365373

366374

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-
375375
static int
376376
ngx_stream_lua_socket_tcp(lua_State *L)
377377
{
@@ -396,8 +396,13 @@ ngx_stream_lua_socket_tcp(lua_State *L)
396396
ngx_stream_lua_check_context(L, ctx, NGX_STREAM_LUA_CONTEXT_CONTENT
397397
| NGX_STREAM_LUA_CONTEXT_TIMER);
398398

399+
<<<<<<< HEAD
399400
lua_createtable(L, 3 /* narr */, 1 /* nrec */);
400401
lua_pushlightuserdata(L, &ngx_stream_lua_tcp_socket_metatable_key);
402+
=======
403+
lua_createtable(L, 4 /* narr */, 1 /* nrec */);
404+
lua_pushlightuserdata(L, &ngx_stream_lua_socket_tcp_metatable_key);
405+
>>>>>>> 75a9f4b... udp downstream api - work in progress
401406
lua_rawget(L, LUA_REGISTRYINDEX);
402407
lua_setmetatable(L, -2);
403408

@@ -3918,14 +3923,22 @@ ngx_stream_lua_socket_cleanup_compiled_pattern(lua_State *L)
39183923
}
39193924

39203925

3926+
void
3927+
ngx_stream_lua_inject_tcp_req_socket_api(lua_State *L)
3928+
{
3929+
lua_pushcfunction(L, ngx_stream_lua_tcp_req_socket);
3930+
lua_setfield(L, -2, "socket");
3931+
}
3932+
3933+
39213934
static int
3922-
ngx_stream_lua_req_socket(lua_State *L)
3935+
ngx_stream_lua_tcp_req_socket(lua_State *L)
39233936
{
39243937
int n, raw;
3938+
ngx_stream_session_t *s;
39253939
ngx_peer_connection_t *pc;
39263940
ngx_stream_lua_srv_conf_t *lscf;
39273941
ngx_connection_t *c;
3928-
ngx_stream_session_t *s;
39293942
ngx_stream_lua_ctx_t *ctx;
39303943
ngx_stream_lua_co_ctx_t *coctx;
39313944
ngx_stream_lua_cleanup_t *cln;
@@ -3956,6 +3969,11 @@ ngx_stream_lua_req_socket(lua_State *L)
39563969

39573970
c = s->connection;
39583971

3972+
if (c->type != SOCK_STREAM) {
3973+
return luaL_error(L, "socket api does not match connection transport",
3974+
lua_gettop(L));
3975+
}
3976+
39593977
#if !defined(nginx_version) || nginx_version < 1003013
39603978
lua_pushnil(L);
39613979
lua_pushliteral(L, "nginx version too old");

src/ngx_stream_lua_socket_tcp.h

Lines changed: 1 addition & 1 deletion
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)