MODBUS_TCP_ACCEPT(3)

πŸ“¦
version 3.1.6 Β· 3 versions
, in debian bookworm

πŸ’– 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