@@ -25,9 +25,7 @@ static int ngx_[% subsys %]_lua_socket_tcp_connect(lua_State *L);
25
25
static int ngx_ [% subsys %]_lua_socket_tcp_sslhandshake (lua_State * L );
26
26
#endif
27
27
static int ngx_ [% subsys %]_lua_socket_tcp_receive (lua_State * L );
28
- [% IF http_subsys %]
29
28
static int ngx_ [% subsys %]_lua_socket_tcp_receiveany (lua_State * L );
30
- [% END %]
31
29
static int ngx_ [% subsys %]_lua_socket_tcp_send (lua_State * L );
32
30
static int ngx_ [% subsys %]_lua_socket_tcp_close (lua_State * L );
33
31
static int ngx_ [% subsys %]_lua_socket_tcp_setoption (lua_State * L );
@@ -106,9 +104,7 @@ static int ngx_[% subsys %]_lua_socket_write_error_retval_handler(
106
104
static ngx_int_t ngx_ [% subsys %]_lua_socket_read_all (void * data , ssize_t bytes );
107
105
static ngx_int_t ngx_ [% subsys %]_lua_socket_read_until (void * data , ssize_t bytes );
108
106
static ngx_int_t ngx_ [% subsys %]_lua_socket_read_chunk (void * data , ssize_t bytes );
109
- [% IF http_subsys %]
110
107
static ngx_int_t ngx_ [% subsys %]_lua_socket_read_any (void * data , ssize_t bytes );
111
- [% END %]
112
108
static int ngx_ [% subsys %]_lua_socket_tcp_receiveuntil (lua_State * L );
113
109
static int ngx_ [% subsys %]_lua_socket_receiveuntil_iterator (lua_State * L );
114
110
static 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)
371
367
/* {{{tcp object metatable */
372
368
lua_pushlightuserdata (L , ngx_ [% subsys %]_lua_lightudata_mask (
373
369
tcp_socket_metatable_key ));
370
+ [% IF http_subsys %]
374
371
lua_createtable (L , 0 /* narr */ , 13 /* nrec */ );
375
372
373
+ [% ELSIF stream_subsys %]
374
+ lua_createtable (L , 0 /* narr */ , 14 /* nrec */ );
375
+ [% END %]
376
+
376
377
lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_connect );
377
378
lua_setfield (L , -2 , "connect" );
378
379
@@ -389,6 +390,9 @@ ngx_[% subsys %]_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
389
390
lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_receiveuntil );
390
391
lua_setfield (L , -2 , "receiveuntil" );
391
392
393
+ lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_receiveany );
394
+ lua_setfield (L , -2 , "receiveany" );
395
+
392
396
lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_send );
393
397
lua_setfield (L , -2 , "send" );
394
398
@@ -413,10 +417,6 @@ ngx_[% subsys %]_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
413
417
[% IF stream_subsys %]
414
418
lua_pushcfunction (L , ngx_ [% subsys %]_lua_socket_tcp_shutdown );
415
419
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" );
420
420
[% END %]
421
421
422
422
lua_pushvalue (L , -1 );
@@ -2478,23 +2478,23 @@ ngx_[% subsys %]_lua_socket_tcp_receive_helper([% req_type %] *r,
2478
2478
}
2479
2479
2480
2480
2481
- [% IF http_subsys %]
2482
2481
static int
2483
2482
ngx_ [% subsys %]_lua_socket_tcp_receiveany (lua_State * L )
2484
2483
{
2485
2484
int n ;
2486
2485
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 ;
2490
2490
2491
2491
n = lua_gettop (L );
2492
2492
if (n != 2 ) {
2493
2493
return luaL_error (L , "expecting 2 arguments "
2494
2494
"(including the object), but got %d" , n );
2495
2495
}
2496
2496
2497
- r = ngx_http_lua_get_req (L );
2497
+ r = ngx_ [% subsys %] _lua_get_req (L );
2498
2498
if (r == NULL ) {
2499
2499
return luaL_error (L , "no request found" );
2500
2500
}
@@ -2506,11 +2506,11 @@ ngx_[% subsys %]_lua_socket_tcp_receiveany(lua_State *L)
2506
2506
2507
2507
if (u == NULL || u -> peer .connection == NULL || u -> read_closed ) {
2508
2508
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 );
2510
2510
2511
2511
if (llcf -> log_socket_errors ) {
2512
2512
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 "
2514
2514
"socket: u:%p, c:%p, ft:%d eof:%d" ,
2515
2515
u , u ? u -> peer .connection : NULL ,
2516
2516
u ? (int ) u -> ft_type : 0 , u ? (int ) u -> eof : 0 );
@@ -2525,8 +2525,8 @@ ngx_[% subsys %]_lua_socket_tcp_receiveany(lua_State *L)
2525
2525
return luaL_error (L , "bad request" );
2526
2526
}
2527
2527
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 );
2530
2530
2531
2531
if (!lua_isnumber (L , 2 )) {
2532
2532
return luaL_argerror (L , 2 , "bad max argument" );
@@ -2537,17 +2537,16 @@ ngx_[% subsys %]_lua_socket_tcp_receiveany(lua_State *L)
2537
2537
return luaL_argerror (L , 2 , "bad max argument" );
2538
2538
}
2539
2539
2540
- u -> input_filter = ngx_http_lua_socket_read_any ;
2540
+ u -> input_filter = ngx_ [% subsys %] _lua_socket_read_any ;
2541
2541
u -> rest = (size_t ) bytes ;
2542
2542
u -> length = u -> rest ;
2543
2543
2544
- ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
2544
+ ngx_log_debug1 (NGX_LOG_DEBUG_ [% SUBSYS %] , r -> connection -> log , 0 ,
2545
2545
"[% log_prefix %]lua tcp socket calling receiveany() "
2546
2546
"method to read at most %uz bytes" , u -> rest );
2547
2547
2548
- return ngx_http_lua_socket_tcp_receive_helper (r , u , L );
2548
+ return ngx_ [% subsys %] _lua_socket_tcp_receive_helper (r , u , L );
2549
2549
}
2550
- [% END %]
2551
2550
2552
2551
2553
2552
static int
@@ -2588,8 +2587,8 @@ ngx_[% subsys %]_lua_socket_tcp_receive(lua_State *L)
2588
2587
2589
2588
if (llcf -> log_socket_errors ) {
2590
2589
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" ,
2593
2592
u , u ? u -> peer .connection : NULL ,
2594
2593
u ? (int ) u -> ft_type : 0 , u ? (int ) u -> eof : 0 );
2595
2594
}
@@ -2732,7 +2731,6 @@ ngx_[% subsys %]_lua_socket_read_line(void *data, ssize_t bytes)
2732
2731
}
2733
2732
2734
2733
2735
- [% IF http_subsys %]
2736
2734
static ngx_int_t
2737
2735
ngx_ [% subsys %]_lua_socket_read_any (void * data , ssize_t bytes )
2738
2736
{
@@ -2751,7 +2749,6 @@ ngx_[% subsys %]_lua_socket_read_any(void *data, ssize_t bytes)
2751
2749
2752
2750
return rc ;
2753
2751
}
2754
- [% END %]
2755
2752
2756
2753
2757
2754
static ngx_int_t
0 commit comments