@@@ much mess, mostly manpages
[mLib] / sel / conn.3.in
CommitLineData
b6b9d458 1.\" -*-nroff-*-
c4ccbbf9
MW
2.\"
3.\" Manual for asynchronous connection
4.\"
5.\" (c) 1999, 2001--2003, 2005, 2007, 2009, 2023, 2024 Straylight/Edgeware
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of the mLib utilities library.
11.\"
12.\" mLib is free software: you can redistribute it and/or modify it under
13.\" the terms of the GNU Library General Public License as published by
14.\" the Free Software Foundation; either version 2 of the License, or (at
15.\" your option) any later version.
16.\"
17.\" mLib is distributed in the hope that it will be useful, but WITHOUT
18.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20.\" License for more details.
21.\"
22.\" You should have received a copy of the GNU Library General Public
23.\" License along with mLib. If not, write to the Free Software
24.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25.\" USA.
26.
27.\"--------------------------------------------------------------------------
28.so ../defs.man \" @@@PRE@@@
29.
30.\"--------------------------------------------------------------------------
31.TH conn 3mLib "23 May 1999" "Straylight/Edgeware" "mLib utilities library"
5934f1ee 32.\" @conn_fd
08da152e 33.\" @conn_init
34.\" @conn_kill
c4ccbbf9
MW
35.
36.\"--------------------------------------------------------------------------
b6b9d458 37.SH NAME
38conn \- selector for nonblocking connections
c4ccbbf9
MW
39.
40.\"--------------------------------------------------------------------------
b6b9d458 41.SH SYNOPSIS
c4ccbbf9 42.
b6b9d458 43.nf
d2a91066 44.B "#include <mLib/conn.h>"
d056fbdf 45.PP
4729aa69 46.B "typedef struct { ...\& } conn;"
d056fbdf 47.PP
adec5584
MW
48.ta \w'\fBint conn_fd('u
49.BI "int conn_fd(conn *" c ", sel_state *" s ", int " fd ,
50.BI " void (*" func ")(int " fd ", void *" p ),
51.BI " void *" p );
d056fbdf 52.PP
adec5584
MW
53.ta \w'\fBint conn_init('u
54.BI "int conn_init(conn *" c ", sel_state *" s ", int " fd ,
55.BI " struct sockaddr *" dst ", int " dsz ,
56.BI " void (*" func ")(int " fd ", void *" p ),
57.BI " void *" p );
d056fbdf 58.PP
b6b9d458 59.BI "void conn_kill(conn *" c );
60.fi
c4ccbbf9
MW
61.
62.\"--------------------------------------------------------------------------
b6b9d458 63.SH DESCRIPTION
c4ccbbf9 64.
b6b9d458 65The
66.B conn
67selector manages a nonblocking connection to a remote socket. The
68selector's state is maintained in an object of type
69.BR conn .
70.PP
71Before use, a
72.B conn
73selector must be initialized. This requires a call to
74.B conn_init
75with a fairly large number of arguments:
76.TP
ff76c38f 77.BI "conn *" c
b6b9d458 78Pointer to
79.B conn
80object which needs to be initialized.
81.TP
ff76c38f 82.BI "sel_state *" s
b6b9d458 83Pointer to a multiplexor object (type
84.BR sel_state )
85to which this selector should be attached. See
08da152e 86.BR sel (3)
b6b9d458 87for more details about multiplexors, and how this whole system works.
88.TP
ff76c38f 89.BI "int " fd
b6b9d458 90File descriptor for the socket you want to connect. This becomes the
91`property' of the
92.B conn
93selector until the connection attempt finishes. For example, if there's
94an error, the descriptor will be closed.
95.TP
ff76c38f 96.BI "struct sockaddr *" dst
b6b9d458 97Pointer to destination socket address for the connection. Make sure
98that the address has the right family.
99.TP
d4efbcd9 100.BI "int " dsz
b6b9d458 101Size of the destination socket address.
102.TP
ff76c38f 103.BI "void (*" func ")(int " fd ", void *" p )
b6b9d458 104A function to call when the connection is complete. It is passed the
105file descriptor of the connected socket, and the pointer passed
106to
107.B conn_init
108as the
109.I p
99c850b2 110argument.
b6b9d458 111.TP
ff76c38f 112.BI "void *" p
b6b9d458 113An arbitrary pointer whose value is passed to the handler function when
114the connection finishes.
115.PP
99c850b2 116A few words are in order about
117.BR conn_init 's
5934f1ee 118detailed behaviour and return value. If it returns \-1, the connection
119attempt has failed immediately, an error code is stored in the global
120variable
121.BR errno ,
99c850b2 122the file descriptor has been
123.IR closed ,
124and the connection function will
125.I not
126be called. If it returns zero, then there has been no immediate
127failure; the connection function
128.I might
129have been called, if the connection succeeded immediately, but it will
130certainly be called some time, unless the connector is killed (see
131.B conn_kill
132below). When the connection function is called, it will either be
133passed the file descriptor of the new-connected socket (to indicate
134success) or the value \-1 for failure; in the latter case, an
135appropriate error code is stored in
136.BR errno .
137.PP
5934f1ee 138Alternatively, if you have a socket with a pending connection (i.e., a
139call to
140.BR connect
d4efbcd9 141returned \-1 and set
5934f1ee 142.B errno
143to
d4efbcd9 144.BR EINPROGRESS ),
5934f1ee 145you can call
146.BR conn_fd.
147Its arguments are the same as for
148.BR conn_init ,
149except that since the socket knows its a peer address the
150.I dst
151and
152.I dsz
153arguments are not given, and it can't fail.
154.PP
b6b9d458 155If you want to cancel the connection attempt before it finishes, call
156.B conn_kill
157with the address of the selector. The file descriptor is closed, and
158the selector becomes safe to be discarded.
c4ccbbf9
MW
159.
160.\"--------------------------------------------------------------------------
08da152e 161.SH "SEE ALSO"
c4ccbbf9 162.
08da152e 163.BR connect (2),
164.BR sel (3),
165.BR mLib (3).
c4ccbbf9
MW
166.
167.\"--------------------------------------------------------------------------
b6b9d458 168.SH AUTHOR
c4ccbbf9 169.
9b5ac6ff 170Mark Wooding, <mdw@distorted.org.uk>
c4ccbbf9
MW
171.
172.\"----- That's all, folks --------------------------------------------------