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 .BI "int conn_fd(conn *" c ", sel_state *" s ", int " fd ,
13 .BI " void (*" func ")(int " fd ", void *" p ),
16 .BI "int conn_init(conn *" c ", sel_state *" s ", int " fd ,
17 .BI " struct sockaddr *" dst ", int " dsz ,
18 .BI " void (*" func ")(int " fd ", void *" p ),
21 .BI "void conn_kill(conn *" c );
26 selector manages a nonblocking connection to a remote socket. The
27 selector's state is maintained in an object of type
32 selector must be initialized. This requires a call to
34 with a fairly large number of arguments:
39 object which needs to be initialized.
42 Pointer to a multiplexor object (type
44 to which this selector should be attached. See
46 for more details about multiplexors, and how this whole system works.
49 File descriptor for the socket you want to connect. This becomes the
52 selector until the connection attempt finishes. For example, if there's
53 an error, the descriptor will be closed.
55 .BI "struct sockaddr *" dst
56 Pointer to destination socket address for the connection. Make sure
57 that the address has the right family.
60 Size of the destination socket address.
62 .BI "void (*" func ")(int " fd ", void *" p )
63 A function to call when the connection is complete. It is passed the
64 file descriptor of the connected socket, and the pointer passed
72 An arbitrary pointer whose value is passed to the handler function when
73 the connection finishes.
75 A few words are in order about
77 detailed behaviour and return value. If it returns \-1, the connection
78 attempt has failed immediately, an error code is stored in the global
81 the file descriptor has been
83 and the connection function will
85 be called. If it returns zero, then there has been no immediate
86 failure; the connection function
88 have been called, if the connection succeeded immediately, but it will
89 certainly be called some time, unless the connector is killed (see
91 below). When the connection function is called, it will either be
92 passed the file descriptor of the new-connected socket (to indicate
93 success) or the value \-1 for failure; in the latter case, an
94 appropriate error code is stored in
97 Alternatively, if you have a socket with a pending connection (i.e., a
106 Its arguments are the same as for
108 except that since the socket knows its a peer address the
112 arguments are not given, and it can't fail.
114 If you want to cancel the connection attempt before it finishes, call
116 with the address of the selector. The file descriptor is closed, and
117 the selector becomes safe to be discarded.
123 Mark Wooding, <mdw@distorted.org.uk>