@@ -95,7 +95,7 @@ static int ngx_stream_lua_socket_receiveuntil_iterator(lua_State *L);
9595static 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 );
9797static 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 );
9999static void ngx_stream_lua_req_socket_rev_handler (ngx_stream_session_t * s ,
100100 ngx_stream_lua_ctx_t * ctx );
101101static int ngx_stream_lua_socket_tcp_getreusedtimes (lua_State * L );
@@ -193,7 +193,7 @@ enum {
193193static char ngx_stream_lua_req_socket_metatable_key ;
194194#endif
195195static 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 ;
197197static char ngx_stream_lua_upstream_udata_metatable_key ;
198198static char ngx_stream_lua_downstream_udata_metatable_key ;
199199static 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-
375367static int
376368ngx_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+
39213921static 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" );
0 commit comments