tarantool / tarantool/doc

`socket.tcp_server_create()` and `socket.tcp_server_loop()`

Open
#5,613 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

socket.tcp_server_create() creates a master socket, performs bind
and listen, and applies the optional prepare callback. It returns
the listening socket and its address.

socket.tcp_server_loop() runs the accept loop for an existing
listening socket and calls the user handler for each connection.

Usage example:

local socket = require('socket')
local fiber = require('fiber')

local function prepare(s)
    s:setsockopt('SOL_SOCKET', 'SO_REUSEADDR', true)
    return 128
end

local function handler(sc)
    sc:write('hello')
    sc:close()
end

local s, addr = socket.tcp_server_create('127.0.0.1', 12340, prepare)
fiber.create(socket.tcp_server_loop, s, handler)

legacy single-call API still works:


local socket = require('socket')

local function prepare(s)
    s:setsockopt('SOL_SOCKET', 'SO_REUSEADDR', true)
    return 128
end

local function handler(sc)
    sc:write('hello')
    sc:close()
end

socket.tcp_server('127.0.0.1', 12340, {prepare=prepare, handler=handler})

Requested by @unera in https://github.com/tarantool/tarantool/commit/1408f36701444b4fa4a7f9f67dee9438770a6bed.

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

The issue describes socket.tcp_server_create(), socket.tcp_server_loop(), and the legacy socket.tcp_server() API with Lua usage examples. Start by locating the socket API documentation and the existing tcp_server() entry; document the two split APIs, their callbacks and return values, while preserving the legacy example.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.