Debian Codegraph @

docs/modbus_set_socket.md

raw symbols SCIP
1 # modbus_set_socket
2
3 ## Name
4
5 modbus_set_socket - set socket of the context
6
7 ## Synopsis
8
9 ```c
10 int modbus_set_socket(modbus_t *ctx, int s);
11 ```
12
13 ## Description
14
15 The *modbus_set_socket()* function shall set the socket or file descriptor in
16 the libmodbus context. This function is useful for managing multiple client
17 connections to the same server.
18
19 ## Return value
20
21 The function shall return 0 if successful. Otherwise it shall return -1 and set errno.
22
23 ## Example
24
25 ```c
26 ctx = modbus_new_tcp("127.0.0.1", 502);
27 server_socket = modbus_tcp_listen(ctx, NB_CONNECTION);
28
29 FD_ZERO(&rdset);
30 FD_SET(server_socket, &rdset);
31
32 /* .... */
33
34 if (FD_ISSET(master_socket, &rdset)) {
35 modbus_set_socket(ctx, master_socket);
36 rc = modbus_receive(ctx, query);
37 if (rc != -1) {
38 modbus_reply(ctx, query, rc, mb_mapping);
39 }
40 }
41 ```
42
43 ## See also
44
45 - [modbus_get_socket](modbus_get_socket.md)