/* -*-c-*-
*
- * $Id: conn.h,v 1.6 2001/06/22 19:35:20 mdw Exp $
+ * $Id: conn.h,v 1.7 2003/11/29 19:10:53 mdw Exp $
*
* Nonblocking connect handling
*
/*----- Revision history --------------------------------------------------*
*
* $Log: conn.h,v $
+ * Revision 1.7 2003/11/29 19:10:53 mdw
+ * Declare and document @conn_fd@.
+ *
* Revision 1.6 2001/06/22 19:35:20 mdw
* Interface change to @conn_init@ -- return error rather than calling the
* function. This reduces the number of different environments the
/*----- Functions provided ------------------------------------------------*/
+/* --- @conn_fd@ --- *
+ *
+ * Arguments: @conn *c@ = pointer to connection block
+ * @sel_state *s@ = pointer to select state to attach to
+ * @int fd@ = file descriptor of socket
+ * @void (*func)(int fd, void *p) = handler function
+ * @void *p@ = argument for the handler function
+ *
+ * Returns: ---
+ *
+ * Use: Sets up a nonblocking connect job. The socket should have a
+ * connect pending for it already.
+ */
+
+void conn_fd(conn */*c*/, sel_state */*s*/, int /*fd*/,
+ void (*/*func*/)(int /*fd*/, void */*p*/),
+ void */*p*/);
+
/* --- @conn_init@ --- *
*
* Arguments: @conn *c@ = pointer to connection block
.\" -*-nroff-*-
.TH conn 3 "23 May 1999" "Straylight/Edgeware" "mLib utilities library"
+.\" @conn_fd
.\" @conn_init
.\" @conn_kill
.SH NAME
.nf
.B "#include <mLib/conn.h>"
+.BI "int conn_fd(conn *" c ", sel_state *" s ", int " fd ,
+.BI " void (*" func ")(int " fd ", void *" p ),
+.BI " void *" p );
+
.BI "int conn_init(conn *" c ", sel_state *" s ", int " fd ,
.BI " struct sockaddr *" dst ", int " dsz ,
.BI " void (*" func ")(int " fd ", void *" p ),
.PP
A few words are in order about
.BR conn_init 's
-detailed behaviour and return value. If the it returns \-1, the
-connection attempt has failed immediately (an error code is stored in
-the global variable
-.BR errno ),
+detailed behaviour and return value. If it returns \-1, the connection
+attempt has failed immediately, an error code is stored in the global
+variable
+.BR errno ,
the file descriptor has been
.IR closed ,
and the connection function will
appropriate error code is stored in
.BR errno .
.PP
+Alternatively, if you have a socket with a pending connection (i.e., a
+call to
+.BR connect
+returned \-1 and set
+.B errno
+to
+.BR EINPROGRESS ),
+you can call
+.BR conn_fd.
+Its arguments are the same as for
+.BR conn_init ,
+except that since the socket knows its a peer address the
+.I dst
+and
+.I dsz
+arguments are not given, and it can't fail.
+.PP
If you want to cancel the connection attempt before it finishes, call
.B conn_kill
with the address of the selector. The file descriptor is closed, and