tarantool / tarantool/doc

Document new socket functions

Open
#3,612 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.0 feature reference
Dominant language
CSS
Stars
15
Forks
49
Avg merge
1d 13h
Merged PRs (30d)
3

Description

Product: Tarantool
Since: 3.0
Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/socket/
SME: @ locker

Details

Two socket module functions and one socket object method were added to
Tarantool 3.0:

  • socket.from_fd(fd): constructs a socket object from the file
    descriptor number. Returns the new socket object on success. Never
    fails. Note, the function doesn't perform any checks on the given
    file descriptor so technically it's possible to pass a closed file
    descriptor or a file descriptor that refers to a file, in which case
    the new socket object methods may not work as expected.

  • socket:detach(): like socket:close() but doesn't close the socket
    file descriptor, only switches the socket object to the closed state.
    Returns nothing. If the socket was already detached or closed, raises
    an exception.

    Along with socket.from_fd, this method may be used for transferring
    file descriptor ownership from one socket to another:

    local socket = require('socket')
    local s1 = socket('AF_INET', 'SOCK_STREAM', 'tcp')
    local s2 = socket.from_fd(s1:fd())
    s1:detach()
    
  • socket.socketpair(domain, type, proto): a wrapper around the
    socketpair system call. Returns two socket objects representing
    the two ends of the new socket pair on success. On failure, returns
    nil and sets errno.

    Example:

    local errno = require('errno')
    local socket = require('socket')
    local s1, s1 = socket.socketpair('AF_UNIX', 'SOCK_STREAM', 0)
    if not s1 then
        error('socketpair: ' .. errno.strerror())
    end
    s1:send('foo')
    assert(s2:recv() == 'foo')
    s1:close()
    s2:close()
    

Requested by @locker in https://github.com/tarantool/tarantool/commit/61130805b15c506657818606f3a85a3b2b32311d.

Definition of done

  • socket.from_fd(fd) module function
  • socket:detach()module function
  • socket.socketpair(domain, type, proto) object method

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the socket module root document at the linked reference page and locate its function and method entries. Document socket.from_fd(fd), socket:detach(), and socket.socketpair(domain, type, proto), including the behavior and examples given in the issue; done means all three Definition of done items are covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
documentation, networking
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.