@@ -25,9 +25,7 @@ static int ngx_[% subsys %]_lua_socket_tcp_connect(lua_State *L);
2525static int ngx_ [% subsys %]_lua_socket_tcp_sslhandshake (lua_State * L );
2626#endif
2727static int ngx_ [% subsys %]_lua_socket_tcp_receive (lua_State * L );
28- [% IF http_subsys %]
2928static int ngx_ [% subsys %]_lua_socket_tcp_receiveany (lua_State * L );
30- [% END %]
3129static int ngx_ [% subsys %]_lua_socket_tcp_send (lua_State * L );
3230static int ngx_ [% subsys %]_lua_socket_tcp_close (lua_State * L );
3331static int ngx_ [% subsys %]_lua_socket_tcp_setoption (lua_State * L );
@@ -106,9 +104,7 @@ static int ngx_[% subsys %]_lua_socket_write_error_retval_handler(
106104static ngx_int_t ngx_ [% subsys %]_lua_socket_read_all (void * data , ssize_t bytes );
107105static ngx_int_t ngx_ [% subsys %]_lua_socket_read_until (void * data , ssize_t bytes );
108106static ngx_int_t ngx_ [% subsys %]_lua_socket_read_chunk (void * data , ssize_t bytes );
109- [% IF http_subsys %]
110107static ngx_int_t ngx_ [% subsys %]_lua_socket_read_any (void * data , ssize_t bytes );
111- [% END %]
112108static int ngx_ [% subsys %]_lua_socket_tcp_receiveuntil (lua_State * L );
113109static int ngx_ [% subsys %]_lua_socket_receiveuntil_iterator (lua_State * L );
114110static ngx_int_t ngx_ [% subsys %]_lua_socket_compile_pattern (u_char * data , size_t len ,
@@ -371,8 +367,13 @@ ngx_[% subsys %]_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
371367 /* {{{tcp object metatable */
372368 lua_pushlightuserdata (L , ngx_ [% subsys %]_lua_lightudata_mask (
373369 tcp_socket_metatable_key ));
370+ [% IF http_subsys %]
374371 lua_createtable (L , 0 /* narr */ , 13 /* nrec */ );
375372
373+ [% ELSIF stream_subsys %]
374+ lua_createtable (L , 0 /* narr */ , 14 /* nrec */ );
375+ [% END %]
376+
376377 lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_connect );
377378 lua_setfield (L , -2 , "connect" );
378379
@@ -389,6 +390,9 @@ ngx_[% subsys %]_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
389390 lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_receiveuntil );
390391 lua_setfield (L , -2 , "receiveuntil" );
391392
393+ lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_receiveany );
394+ lua_setfield (L , -2 , "receiveany" );
395+
392396 lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_send );
393397 lua_setfield (L , -2 , "send" );
394398
@@ -413,10 +417,6 @@ ngx_[% subsys %]_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
413417[% IF stream_subsys %]
414418 lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_shutdown );
415419 lua_setfield (L , -2 , "shutdown" );
416-
417- [% ELSIF http_subsys %]
418- lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_receiveany );
419- lua_setfield (L , -2 , "receiveany" );
420420[% END %]
421421
422422 lua_pushvalue (L , -1 );
@@ -2478,23 +2478,23 @@ ngx_[% subsys %]_lua_socket_tcp_receive_helper([% req_type %] *r,
24782478}
24792479
24802480
2481- [% IF http_subsys %]
24822481static int
24832482ngx_ [% subsys %]_lua_socket_tcp_receiveany (lua_State * L )
24842483{
24852484 int n ;
24862485 lua_Integer bytes ;
2487- ngx_http_request_t * r ;
2488- ngx_http_lua_loc_conf_t * llcf ;
2489- ngx_http_lua_socket_tcp_upstream_t * u ;
2486+ [% req_type %] * r ;
2487+ ngx_ [% subsys %]_lua_loc_conf_t * llcf ;
2488+
2489+ ngx_ [% subsys %]_lua_socket_tcp_upstream_t * u ;
24902490
24912491 n = lua_gettop (L );
24922492 if (n != 2 ) {
24932493 return luaL_error (L , "expecting 2 arguments "
24942494 "(including the object), but got %d" , n );
24952495 }
24962496
2497- r = ngx_http_lua_get_req (L );
2497+ r = ngx_ [% subsys %] _lua_get_req (L );
24982498 if (r == NULL ) {
24992499 return luaL_error (L , "no request found" );
25002500 }
@@ -2506,11 +2506,11 @@ ngx_[% subsys %]_lua_socket_tcp_receiveany(lua_State *L)
25062506
25072507 if (u == NULL || u -> peer .connection == NULL || u -> read_closed ) {
25082508
2509- llcf = ngx_http_get_module_loc_conf (r , ngx_http_lua_module );
2509+ llcf = ngx_ [% req_subsys %] _get_module_loc_conf (r , ngx_ [% subsys %] _lua_module );
25102510
25112511 if (llcf -> log_socket_errors ) {
25122512 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
2513- "[% log_prefix %] attempt to receive data on a closed "
2513+ "attempt to receive data on a closed "
25142514 "socket: u:%p, c:%p, ft:%d eof:%d" ,
25152515 u , u ? u -> peer .connection : NULL ,
25162516 u ? (int ) u -> ft_type : 0 , u ? (int ) u -> eof : 0 );
@@ -2525,8 +2525,8 @@ ngx_[% subsys %]_lua_socket_tcp_receiveany(lua_State *L)
25252525 return luaL_error (L , "bad request" );
25262526 }
25272527
2528- ngx_http_lua_socket_check_busy_connecting (r , u , L );
2529- ngx_http_lua_socket_check_busy_reading (r , u , L );
2528+ ngx_ [% subsys %] _lua_socket_check_busy_connecting (r , u , L );
2529+ ngx_ [% subsys %] _lua_socket_check_busy_reading (r , u , L );
25302530
25312531 if (!lua_isnumber (L , 2 )) {
25322532 return luaL_argerror (L , 2 , "bad max argument" );
@@ -2537,17 +2537,16 @@ ngx_[% subsys %]_lua_socket_tcp_receiveany(lua_State *L)
25372537 return luaL_argerror (L , 2 , "bad max argument" );
25382538 }
25392539
2540- u -> input_filter = ngx_http_lua_socket_read_any ;
2540+ u -> input_filter = ngx_ [% subsys %] _lua_socket_read_any ;
25412541 u -> rest = (size_t ) bytes ;
25422542 u -> length = u -> rest ;
25432543
2544- ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
2544+ ngx_log_debug1 (NGX_LOG_DEBUG_ [% SUBSYS %] , r -> connection -> log , 0 ,
25452545 "[% log_prefix %]lua tcp socket calling receiveany() "
25462546 "method to read at most %uz bytes" , u -> rest );
25472547
2548- return ngx_http_lua_socket_tcp_receive_helper (r , u , L );
2548+ return ngx_ [% subsys %] _lua_socket_tcp_receive_helper (r , u , L );
25492549}
2550- [% END %]
25512550
25522551
25532552static int
@@ -2588,8 +2587,8 @@ ngx_[% subsys %]_lua_socket_tcp_receive(lua_State *L)
25882587
25892588 if (llcf -> log_socket_errors ) {
25902589 ngx_log_error (NGX_LOG_ERR , r -> connection -> log , 0 ,
2591- "attempt to receive data on a closed socket: u:%p, "
2592- "c:%p, ft:%d eof:%d" ,
2590+ "[% log_prefix %] attempt to receive data on a closed "
2591+ "socket: u:%p, c:%p, ft:%d eof:%d" ,
25932592 u , u ? u -> peer .connection : NULL ,
25942593 u ? (int ) u -> ft_type : 0 , u ? (int ) u -> eof : 0 );
25952594 }
@@ -2732,7 +2731,6 @@ ngx_[% subsys %]_lua_socket_read_line(void *data, ssize_t bytes)
27322731}
27332732
27342733
2735- [% IF http_subsys %]
27362734static ngx_int_t
27372735ngx_ [% subsys %]_lua_socket_read_any (void * data , ssize_t bytes )
27382736{
@@ -2751,7 +2749,6 @@ ngx_[% subsys %]_lua_socket_read_any(void *data, ssize_t bytes)
27512749
27522750 return rc ;
27532751}
2754- [% END %]
27552752
27562753
27572754static ngx_int_t
0 commit comments