net.box: allow to create connect from fd
Closes #8928 @TarantoolBot document Title: Document `from_fd` net.box module function The function takes a file descriptor number (fd) as its first argument and a table of connection options as its second, optional argument. It creates and returns a new connection object. The fd should point to a socket and be switched to the non-blocking mode, but this isn't enforced. If the fd is invalid, the connection may not work as expected. The functions takes the same options as [`connect`][net-box-connect]. The function takes the ownership of the fd, i.e. the fd must not be used or closed after this function successfully returns. Example: The code below connects to a Tarantool instance at port 3301 using the [`socket`][socket] module, then wraps the socket fd in a `net.box` connection object. ```Lua local net = require('net.box') local socket = require('socket') -- Connect a socket then wrap it in a net.box connection object. local s = socket.tcp_connect('localhost', 3301) assert(s ~= nil) local conn = net.from_fd(s:fd(), {fetch_schema = false}) s:detach() conn:call('box.schema.user.info') conn:close() ``` [net-box-connect]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/net_box/#net-box-connect [socket]: https://www.tarantool.io/en/doc/latest/reference/reference_lua/socket/
Showing
- changelogs/unreleased/gh-8928-net-box-from-fd.md 4 additions, 0 deletionschangelogs/unreleased/gh-8928-net-box-from-fd.md
- src/box/lua/net_box.c 48 additions, 22 deletionssrc/box/lua/net_box.c
- src/box/lua/net_box.lua 46 additions, 15 deletionssrc/box/lua/net_box.lua
- test/box-luatest/gh_8928_net_box_from_fd_test.lua 144 additions, 0 deletionstest/box-luatest/gh_8928_net_box_from_fd_test.lua
Loading
Please register or sign in to comment