MODBUS_TCP_ACCEPT(3)
π MODBUS_TCP_ACCEPT π
okay bestie, welcome to the libmodbus Manual, section 3 β¨ this is the page for modbus_tcp_accept, aka the glow-up moment where your TCP Modbus server (IPv4 edition π) finally lets a client in the door.
πΈ NAME πΈ
modbus_tcp_accept β accept a new connection on a TCP Modbus socket (IPv4) π«Ά
β¨ SYNOPSIS β¨
int modbus_tcp_accept(modbus_t *ctx, int *'s);
π DESCRIPTION π
so like. the modbus_tcp_accept() function shall extract the first connection on the queue of pending connections, create a brand new socket, and store it in the libmodbus context you handed it as an argument. main character behaviour, honestly π
and listen β if it's available, accept4() with SOCK_CLOEXEC will be called instead of accept(). fancy β¨ iykyk.
π RETURN VALUE π
success? you get a new socket back. slay π
not success? it shall return -1 and set errno. π it's giving error handling.
π¦ EXAMPLE π¦
for the detailed example, go look at the unit-test-server.c source file in the tests directory π
...
ctx = modbus_new_tcp("127.0.0.1", 502);
s = modbus_tcp_listen(ctx, 1);
modbus_tcp_accept(ctx, &s);
...
close(s)
modbus_free(ctx);
look at that flow. setup, listen, accept, cleanup. the way that it just works. periodt π
π SEE ALSO π
π AUTHORS π
the libmodbus documentation was written by StΓ©phane Raimbault <stephane.raimbault@gmail.com> π
aaaand that's the page!! this was libmodbus v3.1.6, dated 11/17/2025 β mwah, no notes, go accept some connections bestie π«Άβ¨π
π¦ where this page comes from
- debian bookworm: libmodbus-dev 3.1.6-2.1+deb12u1 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms