3 .\" Manual for asynchronous connection
5 .\" (c) 1999, 2001--2003, 2005, 2007, 2009, 2023, 2024 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the mLib utilities library.
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.
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.
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,
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
30 .\"--------------------------------------------------------------------------
31 .TH conn 3mLib "23 May 1999" "Straylight/Edgeware" "mLib utilities library"
36 .\"--------------------------------------------------------------------------
38 conn \- selector for nonblocking connections
40 .\"--------------------------------------------------------------------------
44 .B "#include <mLib/conn.h>"
46 .B "typedef struct { ...\& } conn;"
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 ),
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 ),
59 .BI "void conn_kill(conn *" c );
62 .\"--------------------------------------------------------------------------
67 selector manages a nonblocking connection to a remote socket. The
68 selector's state is maintained in an object of type
73 selector must be initialized. This requires a call to
75 with a fairly large number of arguments:
80 object which needs to be initialized.
83 Pointer to a multiplexor object (type
85 to which this selector should be attached. See
87 for more details about multiplexors, and how this whole system works.
90 File descriptor for the socket you want to connect. This becomes the
93 selector until the connection attempt finishes. For example, if there's
94 an error, the descriptor will be closed.
96 .BI "struct sockaddr *" dst
97 Pointer to destination socket address for the connection. Make sure
98 that the address has the right family.
101 Size of the destination socket address.
103 .BI "void (*" func ")(int " fd ", void *" p )
104 A function to call when the connection is complete. It is passed the
105 file descriptor of the connected socket, and the pointer passed
113 An arbitrary pointer whose value is passed to the handler function when
114 the connection finishes.
116 A few words are in order about
118 detailed behaviour and return value. If it returns \-1, the connection
119 attempt has failed immediately, an error code is stored in the global
122 the file descriptor has been
124 and the connection function will
126 be called. If it returns zero, then there has been no immediate
127 failure; the connection function
129 have been called, if the connection succeeded immediately, but it will
130 certainly be called some time, unless the connector is killed (see
132 below). When the connection function is called, it will either be
133 passed the file descriptor of the new-connected socket (to indicate
134 success) or the value \-1 for failure; in the latter case, an
135 appropriate error code is stored in
138 Alternatively, if you have a socket with a pending connection (i.e., a
147 Its arguments are the same as for
149 except that since the socket knows its a peer address the
153 arguments are not given, and it can't fail.
155 If you want to cancel the connection attempt before it finishes, call
157 with the address of the selector. The file descriptor is closed, and
158 the selector becomes safe to be discarded.
160 .\"--------------------------------------------------------------------------
167 .\"--------------------------------------------------------------------------
170 Mark Wooding, <mdw@distorted.org.uk>
172 .\"----- That's all, folks --------------------------------------------------