/* -*-c-*-
*
- * $Id: socket.c,v 1.6 2001/02/03 20:30:03 mdw Exp $
+ * $Id: socket.c,v 1.7 2001/06/22 19:37:00 mdw Exp $
*
* Socket source and target definitions
*
/*----- Revision history --------------------------------------------------*
*
* $Log: socket.c,v $
+ * Revision 1.7 2001/06/22 19:37:00 mdw
+ * New @conn_init@ interface.
+ *
* Revision 1.6 2001/02/03 20:30:03 mdw
* Support re-reading config files on SIGHUP.
*
ssource *s;
} ssept;
-#define SKF_CONN 16u
-#define SKF_BROKEN 32u
-
/*----- Protocol table ----------------------------------------------------*/
static addr_ops *addrs[] = { &inet_ops, &un_ops, 0 };
{
stept *ee = (stept *)e;
- if (ee->e.f & EPF_PENDING) {
- if (ee->e.f & SKF_CONN)
- conn_kill(&ee->c);
- } else {
+ if (ee->e.f & EPF_PENDING)
+ conn_kill(&ee->c);
+ else {
REFFD_DEC(ee->e.in);
REFFD_DEC(ee->e.out);
}
{
stept *e = p;
- /* --- Complicated and subtle --- *
- *
- * This code interacts quite closely with @starget_create@, mainly through
- * flags in the endpoint block.
- *
- * If the connection failed, I log a message (that's easy enough). The
- * behaviour then depends on whether the endpoints have been joined yet.
- * If not, I set @SKF_BROKEN@ and return, so that @starget_create@ can
- * clean up the mess and return an immediate failure. If they have, I kill
- * the connection and everything ought to work.
- *
- * If the connection worked, I clear @EPF_PENDING@ (as expected, because
- * my endpoint is now ready), and @SKF_CONN@ (to let @starget_create@ know
- * that the connection is already going). Then, only if this isn't the
- * first attempt, I rejoin this endpoint to its partner.
- */
-
if (fd == -1) {
fw_log(-1, "[%s] connection failed: %s", e->desc, strerror(errno));
- e->e.f &= ~SKF_CONN;
- if (e->e.f & EPF_PENDING)
- endpt_kill(&e->e);
- else
- e->e.f |= SKF_BROKEN;
+ endpt_kill(&e->e);
} else {
reffd *r = reffd_init(fd);
REFFD_INC(r);
e->e.in = e->e.out = r;
- e->e.f &= ~(EPF_PENDING | SKF_CONN);
+ e->e.f &= ~EPF_PENDING;
if (e->e.other)
endpt_join(&e->e, e->e.other);
}
fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
e->e.ops = &stept_ops;
e->e.other = 0;
- e->e.f = EPF_FILE | SKF_CONN;
+ e->e.f = EPF_FILE | EPF_PENDING;
e->e.t = 0;
e->desc = xstrdup(desc);
- /* --- Pay attention --- *
- *
- * This bit is quite subtle. The connect can succeed or fail later: that's
- * fine. The problem comes if it makes its mind up right now. The flag
- * @SKF_CONN@ signifies that I'm trying to connect. I set it up to begin
- * with and @stept_go@ turns it off when it's done: @stept_close@ uses it
- * to decide whether to kill the connection. The flag @EPF_PENDING@ is
- * only set after @conn_init@ returns and @SKF_CONN@ is still set (meaning
- * that the connection is still in progress). That's used to let
- * @stept_go@ know whether to kill the other endpoint. The flag
- * @SKF_BROKEN@ is used to signify an immediate failure.
- */
-
- conn_init(&e->c, sel, fd, &ga->sa, ga->a.sz, stept_go, e);
- if (e->e.f & SKF_BROKEN) {
+ if (conn_init(&e->c, sel, fd, &ga->sa, ga->a.sz, stept_go, e)) {
+ fw_log(-1, "[%s] connection failed: %s", e->desc, strerror(errno));
DESTROY(e);
return (0);
}
- if (e->e.f & SKF_CONN)
- e->e.f |= EPF_PENDING;
fw_inc();
return (&e->e);
}