@@ -63,6 +63,10 @@ ngx_http_lua_ffi_socket_tcp_get_sslhandshake_result(ngx_http_request_t *r,
63
63
64
64
void
65
65
ngx_http_lua_ffi_ssl_free_session (void * sess );
66
+
67
+ int
68
+ ngx_http_lua_ffi_socket_tcp_getfd (ngx_http_request_t * r ,
69
+ ngx_http_lua_socket_tcp_upstream_t * u , char ** errmsg );
66
70
]]
67
71
68
72
ngx_lua_ffi_socket_tcp_getoption = C .ngx_http_lua_ffi_socket_tcp_getoption
@@ -293,12 +297,40 @@ local function sslhandshake(cosocket, reused_session, server_name, ssl_verify,
293
297
end
294
298
295
299
300
+ local function getfd (cosocket )
301
+ if not cosocket then
302
+ error (" ngx.socket getfd: expecting the cosocket object, but seen none" )
303
+ end
304
+
305
+ local r = get_request ()
306
+ if not r then
307
+ error (" no request found" )
308
+ end
309
+
310
+ local u = get_tcp_socket (cosocket )
311
+
312
+ local fd = C .ngx_http_lua_ffi_socket_tcp_getfd (r , u , errmsg )
313
+ if (fd < 0 ) then
314
+ return nil , ffi_str (errmsg [0 ])
315
+ end
316
+
317
+ return fd ;
318
+ end
319
+
320
+
296
321
do
297
322
local method_table = registry .__tcp_cosocket_mt
298
323
method_table .getoption = getoption
299
324
method_table .setoption = setoption
300
325
method_table .setclientcert = setclientcert
301
326
method_table .sslhandshake = sslhandshake
327
+ method_table .getfd = getfd
328
+
329
+ method_table = registry .__tcp_req_cosocket_mt
330
+ method_table .getfd = getfd
331
+
332
+ method_table = registry .__tcp_raw_req_cosocket_mt
333
+ method_table .getfd = getfd
302
334
end
303
335
304
336
elseif subsystem == ' stream' then
0 commit comments