Commit 9dcfed8189c473bd6308c30fdb783a2124490925
1 parent
c7051e0d
Add documentation for modbus_tcp_listen
Showing
2 changed files
with
71 additions
and
0 deletions
doc/Makefile.am
| @@ -39,6 +39,7 @@ MAN3 = \ | @@ -39,6 +39,7 @@ MAN3 = \ | ||
| 39 | modbus_set_slave.3 \ | 39 | modbus_set_slave.3 \ |
| 40 | modbus_set_socket.3 \ | 40 | modbus_set_socket.3 \ |
| 41 | modbus_strerror.3 \ | 41 | modbus_strerror.3 \ |
| 42 | + modbus_tcp_listen.3 \ | ||
| 42 | modbus_write_and_read_registers.3 \ | 43 | modbus_write_and_read_registers.3 \ |
| 43 | modbus_write_bits.3 \ | 44 | modbus_write_bits.3 \ |
| 44 | modbus_write_bit.3 \ | 45 | modbus_write_bit.3 \ |
doc/modbus_tcp_listen.txt
0 → 100644
| 1 | +modbus_tcp_listen(3) | ||
| 2 | +==================== | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +NAME | ||
| 6 | +---- | ||
| 7 | +modbus_tcp_listen - create and listen a TCP Modbus socket | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +SYNOPSIS | ||
| 11 | +-------- | ||
| 12 | +*int modbus_tcp_listen(modbus_t *'ctx', int 'nb_connection');* | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +DESCRIPTION | ||
| 16 | +----------- | ||
| 17 | +The _modbus_tcp_listen()_ function shall create a socket and listen for | ||
| 18 | +'nb_connection' incoming connections. | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +RETURN VALUE | ||
| 22 | +------------ | ||
| 23 | +The _modbus_tcp_listen()_ function shall return a new socket if | ||
| 24 | +successful. Otherwise it shall return -1 and set errno. | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +EXAMPLE | ||
| 28 | +------- | ||
| 29 | +For a detailed example, see source file bandwith-server-many-up.c provided in | ||
| 30 | +tests directory. | ||
| 31 | + | ||
| 32 | +[source,c] | ||
| 33 | +------------------- | ||
| 34 | +... | ||
| 35 | + | ||
| 36 | +ctx = modbus_new_tcp("127.0.0.1", 502); | ||
| 37 | +if (modbus_connect(ctx) == -1) { | ||
| 38 | + fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno)); | ||
| 39 | + modbus_free(ctx); | ||
| 40 | + return -1; | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +/* Handle until 10 established connections */ | ||
| 44 | +server_socket = modbus_tcp_listen(ctx, 10); | ||
| 45 | + | ||
| 46 | +/* Clear the reference set of socket */ | ||
| 47 | +FD_ZERO(&refset); | ||
| 48 | + | ||
| 49 | +/* Add the server socket */ | ||
| 50 | +FD_SET(server_socket, &refset); | ||
| 51 | + | ||
| 52 | +if (select(server_socket + 1, &refset, NULL, NULL, NULL) == -1) { | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +... | ||
| 56 | + | ||
| 57 | +close(server_socket); | ||
| 58 | +modbus_free(ctx); | ||
| 59 | +------------------- | ||
| 60 | + | ||
| 61 | +SEE ALSO | ||
| 62 | +-------- | ||
| 63 | +linkmb:modbus_tcp_accept[3] | ||
| 64 | +linkmb:modbus_tcp_pi_accept[3] | ||
| 65 | +linkmb:modbus_tcp_pi_listen[3] | ||
| 66 | + | ||
| 67 | +AUTHORS | ||
| 68 | +------- | ||
| 69 | +The libmodbus documentation was written by Stéphane Raimbault | ||
| 70 | +<stephane.raimbault@gmail.com> |