@@ -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
@@ -3919,14 +3911,22 @@ ngx_stream_lua_socket_cleanup_compiled_pattern(lua_State *L)
39193911}
39203912
39213913
3914+ void
3915+ ngx_stream_lua_inject_tcp_req_socket_api (lua_State * L )
3916+ {
3917+ lua_pushcfunction (L , ngx_stream_lua_tcp_req_socket );
3918+ lua_setfield (L , -2 , "socket" );
3919+ }
3920+
3921+
39223922static int
3923- ngx_stream_lua_req_socket (lua_State * L )
3923+ ngx_stream_lua_tcp_req_socket (lua_State * L )
39243924{
39253925 int n , raw ;
3926+ ngx_stream_session_t * s ;
39263927 ngx_peer_connection_t * pc ;
39273928 ngx_stream_lua_srv_conf_t * lscf ;
39283929 ngx_connection_t * c ;
3929- ngx_stream_session_t * s ;
39303930 ngx_stream_lua_ctx_t * ctx ;
39313931 ngx_stream_lua_co_ctx_t * coctx ;
39323932 ngx_stream_lua_cleanup_t * cln ;
@@ -3957,6 +3957,11 @@ ngx_stream_lua_req_socket(lua_State *L)
39573957
39583958 c = s -> connection ;
39593959
3960+ if (c -> type != SOCK_STREAM ) {
3961+ return luaL_error (L , "socket api does not match connection transport" ,
3962+ lua_gettop (L ));
3963+ }
3964+
39603965#if !defined(nginx_version ) || nginx_version < 1003013
39613966 lua_pushnil (L );
39623967 lua_pushliteral (L , "nginx version too old" );
0 commit comments