Commit 2076d11f3e877d99962b95b686b70a74ea82315d

Authored by Stéphane Raimbault
1 parent 900aa475

Add documentation for tcp[_pi]_accept (closes #31)

doc/Makefile.am
@@ -45,6 +45,8 @@ MAN3 = \ @@ -45,6 +45,8 @@ MAN3 = \
45 modbus_set_slave.3 \ 45 modbus_set_slave.3 \
46 modbus_set_socket.3 \ 46 modbus_set_socket.3 \
47 modbus_strerror.3 \ 47 modbus_strerror.3 \
  48 + modbus_tcp_accept.3 \
  49 + modbus_tcp_pi_accept.3 \
48 modbus_tcp_listen.3 \ 50 modbus_tcp_listen.3 \
49 modbus_tcp_pi_listen.3 \ 51 modbus_tcp_pi_listen.3 \
50 modbus_write_and_read_registers.3 \ 52 modbus_write_and_read_registers.3 \
doc/modbus_tcp_accept.txt 0 → 100644
  1 +modbus_tcp_accept(3)
  2 +====================
  3 +
  4 +
  5 +NAME
  6 +----
  7 +modbus_tcp_accept - accept a new connection on a TCP Modbus socket (IPv4)
  8 +
  9 +
  10 +SYNOPSIS
  11 +--------
  12 +*int modbus_tcp_accept(modbus_t *'ctx', int *'s);*
  13 +
  14 +
  15 +DESCRIPTION
  16 +-----------
  17 +The _modbus_tcp_accept()_ function shall extract the first connection on the
  18 +queue of pending connections, create a new socket and store it in libmodbus
  19 +context given in argument. If available, _accept4()_ with *SOCK_CLOEXEC* will be
  20 +called instead of _accept()_.
  21 +
  22 +
  23 +RETURN VALUE
  24 +------------
  25 +The _modbus_tcp_accept()_ function shall return a new socket if successful.
  26 +Otherwise it shall return -1 and set errno.
  27 +
  28 +
  29 +EXAMPLE
  30 +-------
  31 +For detailed example, see unit-test-server.c source file in tests directory.
  32 +
  33 +[source,c]
  34 +-------------------
  35 +...
  36 +
  37 +ctx = modbus_new_tcp("127.0.0.1", 502);
  38 +s = modbus_tcp_listen(ctx, 1);
  39 +modbus_tcp_accept(ctx, &s);
  40 +
  41 +...
  42 +
  43 +close(s)
  44 +modbus_free(ctx);
  45 +-------------------
  46 +
  47 +SEE ALSO
  48 +--------
  49 +linkmb:modbus_tcp_pi_accept[3]
  50 +linkmb:modbus_tcp_listen[3]
  51 +linkmb:modbus_tcp_pi_listen[3]
  52 +
  53 +AUTHORS
  54 +-------
  55 +The libmodbus documentation was written by Stéphane Raimbault
  56 +<stephane.raimbault@gmail.com>
doc/modbus_tcp_pi_accept.txt 0 → 100644
  1 +modbus_tcp_pi_accept(3)
  2 +=======================
  3 +
  4 +
  5 +NAME
  6 +----
  7 +modbus_tcp_pi_accept - accept a new connection on a TCP PI Modbus socket (IPv6)
  8 +
  9 +
  10 +SYNOPSIS
  11 +--------
  12 +*int modbus_tcp_pi_accept(modbus_t *'ctx', int *'s);*
  13 +
  14 +
  15 +DESCRIPTION
  16 +-----------
  17 +
  18 +The _modbus_tcp_pi_accept()_ function shall extract the first connection on the
  19 +queue of pending connections, create a new socket and store it in libmodbus
  20 +context given in argument. If available, _accept4()_ with *SOCK_CLOEXEC* will be
  21 +called instead of _accept()_.
  22 +
  23 +
  24 +RETURN VALUE
  25 +------------
  26 +The _modbus_tcp_pi_accept()_ function shall return a new socket if successful.
  27 +Otherwise it shall return -1 and set errno.
  28 +
  29 +
  30 +EXAMPLE
  31 +-------
  32 +For detailed example, see unit-test-server.c source file in tests directory.
  33 +
  34 +[source,c]
  35 +-------------------
  36 +...
  37 +
  38 +ctx = modbus_new_tcp_pi("::0", 502);
  39 +s = modbus_tcp_pi_listen(ctx, 1);
  40 +modbus_tcp_pi_accept(ctx, &s);
  41 +
  42 +...
  43 +
  44 +close(s)
  45 +modbus_free(ctx);
  46 +-------------------
  47 +
  48 +SEE ALSO
  49 +--------
  50 +linkmb:modbus_tcp_pi_accept[3]
  51 +linkmb:modbus_tcp_listen[3]
  52 +linkmb:modbus_tcp_pi_listen[3]
  53 +
  54 +AUTHORS
  55 +-------
  56 +The libmodbus documentation was written by Stéphane Raimbault
  57 +<stephane.raimbault@gmail.com>
src/modbus-tcp.c
@@ -621,9 +621,6 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection) @@ -621,9 +621,6 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
621 return new_s; 621 return new_s;
622 } 622 }
623 623
624 -/* On success, the function return a non-negative integer that is a descriptor  
625 -for the accepted socket. On error, socket is set to -1, -1 is returned and errno  
626 -is set appropriately. */  
627 int modbus_tcp_accept(modbus_t *ctx, int *s) 624 int modbus_tcp_accept(modbus_t *ctx, int *s)
628 { 625 {
629 struct sockaddr_in addr; 626 struct sockaddr_in addr;