@@ -96,7 +96,7 @@ static int ngx_stream_lua_socket_receiveuntil_iterator(lua_State *L);
9696static 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 );
9898static 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 );
100100static void ngx_stream_lua_req_socket_rev_handler (ngx_stream_session_t * s ,
101101 ngx_stream_lua_ctx_t * ctx );
102102static int ngx_stream_lua_socket_tcp_getreusedtimes (lua_State * L );
@@ -197,7 +197,7 @@ enum {
197197static char ngx_stream_lua_req_socket_metatable_key ;
198198#endif
199199static 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 ;
201201static char ngx_stream_lua_upstream_udata_metatable_key ;
202202static char ngx_stream_lua_downstream_udata_metatable_key ;
203203static 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-
395387static int
396388ngx_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+
40504050static 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" );
0 commit comments