@@ -96,7 +96,7 @@ static int ngx_stream_lua_socket_receiveuntil_iterator(lua_State *L);
96
96
static ngx_int_t ngx_stream_lua_socket_compile_pattern (u_char * data , size_t len ,
97
97
ngx_stream_lua_socket_compiled_pattern_t * cp , ngx_log_t * log );
98
98
static 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 );
100
100
static void ngx_stream_lua_req_socket_rev_handler (ngx_stream_session_t * s ,
101
101
ngx_stream_lua_ctx_t * ctx );
102
102
static int ngx_stream_lua_socket_tcp_getreusedtimes (lua_State * L );
@@ -197,7 +197,7 @@ enum {
197
197
static char ngx_stream_lua_req_socket_metatable_key ;
198
198
#endif
199
199
static 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 ;
201
201
static char ngx_stream_lua_upstream_udata_metatable_key ;
202
202
static char ngx_stream_lua_downstream_udata_metatable_key ;
203
203
static 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)
293
293
/* }}} */
294
294
295
295
/* {{{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 );
297
297
lua_createtable (L , 0 /* narr */ , 12 /* nrec */ );
298
298
299
299
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)
384
384
}
385
385
386
386
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
-
395
387
static int
396
388
ngx_stream_lua_socket_tcp (lua_State * L )
397
389
{
@@ -417,7 +409,7 @@ ngx_stream_lua_socket_tcp(lua_State *L)
417
409
| NGX_STREAM_LUA_CONTEXT_TIMER );
418
410
419
411
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 );
421
413
lua_rawget (L , LUA_REGISTRYINDEX );
422
414
lua_setmetatable (L , -2 );
423
415
@@ -4047,14 +4039,22 @@ ngx_stream_lua_socket_cleanup_compiled_pattern(lua_State *L)
4047
4039
}
4048
4040
4049
4041
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
+
4050
4050
static int
4051
- ngx_stream_lua_req_socket (lua_State * L )
4051
+ ngx_stream_lua_tcp_req_socket (lua_State * L )
4052
4052
{
4053
4053
int n , raw ;
4054
+ ngx_stream_session_t * s ;
4054
4055
ngx_peer_connection_t * pc ;
4055
4056
ngx_stream_lua_srv_conf_t * lscf ;
4056
4057
ngx_connection_t * c ;
4057
- ngx_stream_session_t * s ;
4058
4058
ngx_stream_lua_ctx_t * ctx ;
4059
4059
ngx_stream_lua_co_ctx_t * coctx ;
4060
4060
ngx_stream_lua_cleanup_t * cln ;
@@ -4085,6 +4085,11 @@ ngx_stream_lua_req_socket(lua_State *L)
4085
4085
4086
4086
c = s -> connection ;
4087
4087
4088
+ if (c -> type != SOCK_STREAM ) {
4089
+ return luaL_error (L , "socket api does not match connection transport" ,
4090
+ lua_gettop (L ));
4091
+ }
4092
+
4088
4093
#if !defined(nginx_version ) || nginx_version < 1003013
4089
4094
lua_pushnil (L );
4090
4095
lua_pushliteral (L , "nginx version too old" );
0 commit comments