@@ -95,7 +95,7 @@ static int ngx_stream_lua_socket_receiveuntil_iterator(lua_State *L);
95
95
static ngx_int_t ngx_stream_lua_socket_compile_pattern (u_char * data , size_t len ,
96
96
ngx_stream_lua_socket_compiled_pattern_t * cp , ngx_log_t * log );
97
97
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 );
99
99
static void ngx_stream_lua_req_socket_rev_handler (ngx_stream_session_t * s ,
100
100
ngx_stream_lua_ctx_t * ctx );
101
101
static int ngx_stream_lua_socket_tcp_getreusedtimes (lua_State * L );
@@ -193,7 +193,7 @@ enum {
193
193
static char ngx_stream_lua_req_socket_metatable_key ;
194
194
#endif
195
195
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 ;
197
197
static char ngx_stream_lua_upstream_udata_metatable_key ;
198
198
static char ngx_stream_lua_downstream_udata_metatable_key ;
199
199
static 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)
276
276
/* }}} */
277
277
278
278
/* {{{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 );
280
280
lua_createtable (L , 0 /* narr */ , 11 /* nrec */ );
281
281
282
282
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)
364
364
}
365
365
366
366
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
-
375
367
static int
376
368
ngx_stream_lua_socket_tcp (lua_State * L )
377
369
{
@@ -397,7 +389,7 @@ ngx_stream_lua_socket_tcp(lua_State *L)
397
389
| NGX_STREAM_LUA_CONTEXT_TIMER );
398
390
399
391
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 );
401
393
lua_rawget (L , LUA_REGISTRYINDEX );
402
394
lua_setmetatable (L , -2 );
403
395
@@ -3918,14 +3910,22 @@ ngx_stream_lua_socket_cleanup_compiled_pattern(lua_State *L)
3918
3910
}
3919
3911
3920
3912
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
+
3921
3921
static int
3922
- ngx_stream_lua_req_socket (lua_State * L )
3922
+ ngx_stream_lua_tcp_req_socket (lua_State * L )
3923
3923
{
3924
3924
int n , raw ;
3925
+ ngx_stream_session_t * s ;
3925
3926
ngx_peer_connection_t * pc ;
3926
3927
ngx_stream_lua_srv_conf_t * lscf ;
3927
3928
ngx_connection_t * c ;
3928
- ngx_stream_session_t * s ;
3929
3929
ngx_stream_lua_ctx_t * ctx ;
3930
3930
ngx_stream_lua_co_ctx_t * coctx ;
3931
3931
ngx_stream_lua_cleanup_t * cln ;
@@ -3956,6 +3956,11 @@ ngx_stream_lua_req_socket(lua_State *L)
3956
3956
3957
3957
c = s -> connection ;
3958
3958
3959
+ if (c -> type != SOCK_STREAM ) {
3960
+ return luaL_error (L , "socket api does not match connection transport" ,
3961
+ lua_gettop (L ));
3962
+ }
3963
+
3959
3964
#if !defined(nginx_version ) || nginx_version < 1003013
3960
3965
lua_pushnil (L );
3961
3966
lua_pushliteral (L , "nginx version too old" );
0 commit comments