'\" t
.\" Title: modbus_set_socket
.\" Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1
.\" Date: 02/28/2020
.\" Manual: libmodbus Manual
.\" Source: libmodbus v3.1.6
.\" Language: English
.\"
.TH "MODBUS_SET_SOCKET" "3" "02/28/2020" "libmodbus v3\&.1\&.6" "libmodbus Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
modbus_set_socket \- set socket of the context
.SH "SYNOPSIS"
.sp
\fBint modbus_set_socket(modbus_t *\fR\fB\fIctx\fR\fR\fB, int \fR\fB\fIs\fR\fR\fB);\fR
.SH "DESCRIPTION"
.sp
The \fBmodbus_set_socket()\fR function shall set the socket or file descriptor in the libmodbus context\&. This function is useful for managing multiple client connections to the same server\&.
.SH "RETURN VALUE"
.sp
The function shall return 0 if successful\&. Otherwise it shall return \-1 and set errno\&.
.SH "EXAMPLE"
.sp
.if n \{\
.RS 4
.\}
.nf
ctx = modbus_new_tcp("127\&.0\&.0\&.1", 1502);
server_socket = modbus_tcp_listen(ctx, NB_CONNECTION);
FD_ZERO(&rdset);
FD_SET(server_socket, &rdset);
/* \&.\&.\&.\&. */
if (FD_ISSET(master_socket, &rdset)) {
modbus_set_socket(ctx, master_socket);
rc = modbus_receive(ctx, query);
if (rc != \-1) {
modbus_reply(ctx, query, rc, mb_mapping);
}
}
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.sp
\fBmodbus_get_socket\fR(3)
.SH "AUTHORS"
.sp
The libmodbus documentation was written by Stéphane Raimbault