@@ -227,6 +227,10 @@ static char ngx_http_lua_pattern_udata_metatable_key;
227227
228228
229229#define ngx_http_lua_tcp_socket_metatable_literal_key "__tcp_cosocket_mt"
230+ #define ngx_http_lua_tcp_req_socket_metatable_literal_key \
231+ "__tcp_req_cosocket_mt"
232+ #define ngx_http_lua_tcp_raw_req_socket_metatable_literal_key \
233+ "__tcp_raw_req_cosocket_mt"
230234
231235
232236void
@@ -283,6 +287,12 @@ ngx_http_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
283287 lua_pushvalue (L , -1 );
284288 lua_setfield (L , -2 , "__index" );
285289
290+ lua_rawset (L , LUA_REGISTRYINDEX );
291+
292+ lua_pushliteral (L , ngx_http_lua_tcp_req_socket_metatable_literal_key );
293+ lua_pushlightuserdata (L , ngx_http_lua_lightudata_mask (
294+ req_socket_metatable_key ));
295+ lua_rawget (L , LUA_REGISTRYINDEX );
286296 lua_rawset (L , LUA_REGISTRYINDEX );
287297 /* }}} */
288298
@@ -312,6 +322,12 @@ ngx_http_lua_inject_socket_tcp_api(ngx_log_t *log, lua_State *L)
312322 lua_pushvalue (L , -1 );
313323 lua_setfield (L , -2 , "__index" );
314324
325+ lua_rawset (L , LUA_REGISTRYINDEX );
326+
327+ lua_pushliteral (L , ngx_http_lua_tcp_raw_req_socket_metatable_literal_key );
328+ lua_pushlightuserdata (L , ngx_http_lua_lightudata_mask (
329+ raw_req_socket_metatable_key ));
330+ lua_rawget (L , LUA_REGISTRYINDEX );
315331 lua_rawset (L , LUA_REGISTRYINDEX );
316332 /* }}} */
317333
@@ -6684,6 +6700,28 @@ ngx_http_lua_ffi_socket_tcp_setoption(ngx_http_lua_socket_tcp_upstream_t *u,
66846700}
66856701
66866702
6703+ int
6704+ ngx_http_lua_ffi_socket_tcp_getfd (ngx_http_request_t * r ,
6705+ ngx_http_lua_socket_tcp_upstream_t * u , const char * * errmsg )
6706+ {
6707+ int fd ;
6708+
6709+ * errmsg = NULL ;
6710+
6711+ if (u == NULL || u -> peer .connection == NULL ) {
6712+ * errmsg = "closed" ;
6713+ return -1 ;
6714+ }
6715+
6716+ fd = u -> peer .connection -> fd ;
6717+ if (fd == -1 ) {
6718+ * errmsg = "faked connection" ;
6719+ }
6720+
6721+ return fd ;
6722+ }
6723+
6724+
66876725/* just hack the fd for testing bad case, it will also return the original fd */
66886726int
66896727ngx_http_lua_ffi_socket_tcp_hack_fd (ngx_http_lua_socket_tcp_upstream_t * u ,
0 commit comments