Skip to content
Snippets Groups Projects
Commit ae441c99 authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Vladimir Davydov
Browse files

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/
parent 71ad0da3
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment