• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tarantool / tarantool / 22770960916

06 Mar 2026 03:53PM UTC coverage: 87.678% (+0.01%) from 87.664%
22770960916

push

github

sergepetrenko
lua: split tcp_server into create and loop

Expose `tcp_server_create` and `tcp_server_loop` so that a listening
socket and accept loop could be driven from different threads without
changing the existing tcp_server behavior.

closes: #12343

@TarantoolBot document
Title: `socket.tcp_server_create()` and `socket.tcp_server_loop()`

`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:

```lua
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:

```lua

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})

```

70435 of 118498 branches covered (59.44%)

105947 of 120837 relevant lines covered (87.68%)

1383835.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.94
/src/lua/socket.c


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc