2 .TH conn 3 "23 May 1999" "Straylight/Edgeware" "mLib utilities library"
7 conn \- selector for nonblocking connections
10 .B "#include <mLib/conn.h>"
12 .ds mT \fBint conn_fd(
13 .BI "\*(mTconn *" c ", sel_state *" s ", int " fd ,
14 .BI "\h'\w'\*(mT'u'void (*" func ")(int " fd ", void *" p ),
15 .BI "\h'\w'\*(mT'u'void *" p );
17 .ds mT \fBint conn_init(
18 .BI "\*(mTconn *" c ", sel_state *" s ", int " fd ,
19 .BI "\h'\w'\*(mT'u'struct sockaddr *" dst ", int " dsz ,
20 .BI "\h'\w'\*(mT'u'void (*" func ")(int " fd ", void *" p ),
21 .BI "\h'\w'\*(mT'u'void *" p );
23 .BI "void conn_kill(conn *" c );
28 selector manages a nonblocking connection to a remote socket. The
29 selector's state is maintained in an object of type
34 selector must be initialized. This requires a call to
36 with a fairly large number of arguments:
41 object which needs to be initialized.
44 Pointer to a multiplexor object (type
46 to which this selector should be attached. See
48 for more details about multiplexors, and how this whole system works.
51 File descriptor for the socket you want to connect. This becomes the
54 selector until the connection attempt finishes. For example, if there's
55 an error, the descriptor will be closed.
57 .BI "struct sockaddr *" dst
58 Pointer to destination socket address for the connection. Make sure
59 that the address has the right family.
62 Size of the destination socket address.
64 .BI "void (*" func ")(int " fd ", void *" p )
65 A function to call when the connection is complete. It is passed the
66 file descriptor of the connected socket, and the pointer passed
74 An arbitrary pointer whose value is passed to the handler function when
75 the connection finishes.
77 A few words are in order about
79 detailed behaviour and return value. If it returns \-1, the connection
80 attempt has failed immediately, an error code is stored in the global
83 the file descriptor has been
85 and the connection function will
87 be called. If it returns zero, then there has been no immediate
88 failure; the connection function
90 have been called, if the connection succeeded immediately, but it will
91 certainly be called some time, unless the connector is killed (see
93 below). When the connection function is called, it will either be
94 passed the file descriptor of the new-connected socket (to indicate
95 success) or the value \-1 for failure; in the latter case, an
96 appropriate error code is stored in
99 Alternatively, if you have a socket with a pending connection (i.e., a
108 Its arguments are the same as for
110 except that since the socket knows its a peer address the
114 arguments are not given, and it can't fail.
116 If you want to cancel the connection attempt before it finishes, call
118 with the address of the selector. The file descriptor is closed, and
119 the selector becomes safe to be discarded.
125 Mark Wooding, <mdw@distorted.org.uk>