From 2076d11f3e877d99962b95b686b70a74ea82315d Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Thu, 10 Oct 2013 19:35:49 +0200 Subject: [PATCH] Add documentation for tcp[_pi]_accept (closes #31) --- doc/Makefile.am | 2 ++ doc/modbus_tcp_accept.txt | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ doc/modbus_tcp_pi_accept.txt | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/modbus-tcp.c | 3 --- 4 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 doc/modbus_tcp_accept.txt create mode 100644 doc/modbus_tcp_pi_accept.txt diff --git a/doc/Makefile.am b/doc/Makefile.am index b57f5ae..9f7e282 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -45,6 +45,8 @@ MAN3 = \ modbus_set_slave.3 \ modbus_set_socket.3 \ modbus_strerror.3 \ + modbus_tcp_accept.3 \ + modbus_tcp_pi_accept.3 \ modbus_tcp_listen.3 \ modbus_tcp_pi_listen.3 \ modbus_write_and_read_registers.3 \ diff --git a/doc/modbus_tcp_accept.txt b/doc/modbus_tcp_accept.txt new file mode 100644 index 0000000..e8acf89 --- /dev/null +++ b/doc/modbus_tcp_accept.txt @@ -0,0 +1,56 @@ +modbus_tcp_accept(3) +==================== + + +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 +----------- +The _modbus_tcp_accept()_ function shall extract the first connection on the +queue of pending connections, create a new socket and store it in libmodbus +context given in argument. If available, _accept4()_ with *SOCK_CLOEXEC* will be +called instead of _accept()_. + + +RETURN VALUE +------------ +The _modbus_tcp_accept()_ function shall return a new socket if successful. +Otherwise it shall return -1 and set errno. + + +EXAMPLE +------- +For detailed example, see unit-test-server.c source file in tests directory. + +[source,c] +------------------- +... + +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); +------------------- + +SEE ALSO +-------- +linkmb:modbus_tcp_pi_accept[3] +linkmb:modbus_tcp_listen[3] +linkmb:modbus_tcp_pi_listen[3] + +AUTHORS +------- +The libmodbus documentation was written by Stéphane Raimbault + diff --git a/doc/modbus_tcp_pi_accept.txt b/doc/modbus_tcp_pi_accept.txt new file mode 100644 index 0000000..7ec7602 --- /dev/null +++ b/doc/modbus_tcp_pi_accept.txt @@ -0,0 +1,57 @@ +modbus_tcp_pi_accept(3) +======================= + + +NAME +---- +modbus_tcp_pi_accept - accept a new connection on a TCP PI Modbus socket (IPv6) + + +SYNOPSIS +-------- +*int modbus_tcp_pi_accept(modbus_t *'ctx', int *'s);* + + +DESCRIPTION +----------- + +The _modbus_tcp_pi_accept()_ function shall extract the first connection on the +queue of pending connections, create a new socket and store it in libmodbus +context given in argument. If available, _accept4()_ with *SOCK_CLOEXEC* will be +called instead of _accept()_. + + +RETURN VALUE +------------ +The _modbus_tcp_pi_accept()_ function shall return a new socket if successful. +Otherwise it shall return -1 and set errno. + + +EXAMPLE +------- +For detailed example, see unit-test-server.c source file in tests directory. + +[source,c] +------------------- +... + +ctx = modbus_new_tcp_pi("::0", 502); +s = modbus_tcp_pi_listen(ctx, 1); +modbus_tcp_pi_accept(ctx, &s); + +... + +close(s) +modbus_free(ctx); +------------------- + +SEE ALSO +-------- +linkmb:modbus_tcp_pi_accept[3] +linkmb:modbus_tcp_listen[3] +linkmb:modbus_tcp_pi_listen[3] + +AUTHORS +------- +The libmodbus documentation was written by Stéphane Raimbault + diff --git a/src/modbus-tcp.c b/src/modbus-tcp.c index 8a57f77..dcdb208 100644 --- a/src/modbus-tcp.c +++ b/src/modbus-tcp.c @@ -621,9 +621,6 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection) return new_s; } -/* On success, the function return a non-negative integer that is a descriptor -for the accepted socket. On error, socket is set to -1, -1 is returned and errno -is set appropriately. */ int modbus_tcp_accept(modbus_t *ctx, int *s) { struct sockaddr_in addr; -- libgit2 0.21.4