]> git.ozlabs.org Git - ccan/commitdiff
ccan/io: implement debug.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 4 Aug 2014 08:14:21 +0000 (17:44 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 4 Aug 2014 08:14:21 +0000 (17:44 +0930)
Now a simple flag, with an external toggle (no compile time DEBUG
define required).  But it's completely synchronous.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
34 files changed:
ccan/io/_info
ccan/io/backend.h
ccan/io/io.c
ccan/io/io.h
ccan/io/io_plan.h
ccan/io/poll.c
ccan/io/test/run-01-start-finish-debug.c [new file with mode: 0644]
ccan/io/test/run-01-start-finish.c
ccan/io/test/run-02-read-debug.c [new file with mode: 0644]
ccan/io/test/run-02-read.c
ccan/io/test/run-03-readpartial-debug.c [new file with mode: 0644]
ccan/io/test/run-03-readpartial.c
ccan/io/test/run-04-writepartial-debug.c [new file with mode: 0644]
ccan/io/test/run-04-writepartial.c
ccan/io/test/run-05-write-debug.c [new file with mode: 0644]
ccan/io/test/run-05-write.c
ccan/io/test/run-06-idle.c
ccan/io/test/run-07-break-debug.c [new file with mode: 0644]
ccan/io/test/run-07-break.c
ccan/io/test/run-09-connect-debug.c [new file with mode: 0644]
ccan/io/test/run-09-connect.c
ccan/io/test/run-12-bidir-debug.c [new file with mode: 0644]
ccan/io/test/run-12-bidir.c
ccan/io/test/run-14-duplex-both-read-debug.c [new file with mode: 0644]
ccan/io/test/run-14-duplex-both-read.c
ccan/io/test/run-15-timeout.c
ccan/io/test/run-16-duplex-test-debug.c [new file with mode: 0644]
ccan/io/test/run-16-duplex-test.c
ccan/io/test/run-17-homemade-io-debug.c [new file with mode: 0644]
ccan/io/test/run-17-homemade-io.c
ccan/io/test/run-18-errno-debug.c [new file with mode: 0644]
ccan/io/test/run-18-errno.c
ccan/io/test/run-19-always-debug.c [new file with mode: 0644]
ccan/io/test/run-19-always.c

index 2e0018ad066ace8029873b42c4217aae8ee29b00..42b71d9e6e9f18a48b278ddb5beed8a7ec8c4396 100644 (file)
@@ -133,6 +133,7 @@ int main(int argc, char *argv[])
                return 1;
 
        if (strcmp(argv[1], "depends") == 0) {
                return 1;
 
        if (strcmp(argv[1], "depends") == 0) {
+               printf("ccan/container_of\n");
                printf("ccan/list\n");
                printf("ccan/tal\n");
                printf("ccan/time\n");
                printf("ccan/list\n");
                printf("ccan/tal\n");
                printf("ccan/time\n");
index 44e64ab165583765cea22a5e08a374eaf5c7dfdc..9f8c546c06a6a28135f8ffe2d2176e009e1e6b34 100644 (file)
@@ -25,6 +25,9 @@ struct io_listener {
 /* One connection per client. */
 struct io_conn {
        struct fd fd;
 /* One connection per client. */
 struct io_conn {
        struct fd fd;
+       bool debug;
+       /* For duplex to save. */
+       bool debug_saved;
 
        /* always or closing list. */
        struct io_conn *list;
 
        /* always or closing list. */
        struct io_conn *list;
@@ -44,7 +47,7 @@ void del_listener(struct io_listener *l);
 void backend_new_closing(struct io_conn *conn);
 void backend_new_always(struct io_conn *conn);
 void backend_new_plan(struct io_conn *conn);
 void backend_new_closing(struct io_conn *conn);
 void backend_new_always(struct io_conn *conn);
 void backend_new_plan(struct io_conn *conn);
-
+void remove_from_always(struct io_conn *conn);
 void backend_plan_done(struct io_conn *conn);
 
 void backend_wake(const void *wait);
 void backend_plan_done(struct io_conn *conn);
 
 void backend_wake(const void *wait);
index 23e8070485663dc2ee04d5b81b4efd05fb6f2493..85d4654dcb52da93197c11d9bc4e89bf0556995c 100644 (file)
@@ -10,6 +10,7 @@
 #include <assert.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <assert.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <ccan/container_of/container_of.h>
 
 void *io_loop_return;
 
 
 void *io_loop_return;
 
@@ -80,6 +81,7 @@ struct io_conn *io_new_conn_(const tal_t *ctx, int fd,
        conn->finish = NULL;
        conn->finish_arg = NULL;
        conn->list = NULL;
        conn->finish = NULL;
        conn->finish_arg = NULL;
        conn->list = NULL;
+       conn->debug = false;
 
        if (!add_conn(conn))
                return tal_free(conn);
 
        if (!add_conn(conn))
                return tal_free(conn);
@@ -116,12 +118,9 @@ static struct io_plan *set_always(struct io_conn *conn,
                                                          void *),
                                  void *arg)
 {
                                                          void *),
                                  void *arg)
 {
-       plan->next = next;
-       plan->next_arg = arg;
        plan->status = IO_ALWAYS;
        plan->status = IO_ALWAYS;
-
        backend_new_always(conn);
        backend_new_always(conn);
-       return plan;
+       return io_set_plan(conn, plan, NULL, next, arg);
 }
 
 struct io_plan *io_always_(struct io_conn *conn,
 }
 
 struct io_plan *io_always_(struct io_conn *conn,
@@ -138,9 +137,7 @@ struct io_plan *io_always_(struct io_conn *conn,
                plan = io_get_plan(conn, IO_OUT);
 
        assert(next);
                plan = io_get_plan(conn, IO_OUT);
 
        assert(next);
-       set_always(conn, plan, next, arg);
-
-       return plan;
+       return set_always(conn, plan, next, arg);
 }
 
 static int do_write(int fd, struct io_plan *plan)
 }
 
 static int do_write(int fd, struct io_plan *plan)
@@ -161,18 +158,13 @@ struct io_plan *io_write_(struct io_conn *conn, const void *data, size_t len,
 {
        struct io_plan *plan = io_get_plan(conn, IO_OUT);
 
 {
        struct io_plan *plan = io_get_plan(conn, IO_OUT);
 
-       assert(next);
-
        if (len == 0)
                return set_always(conn, plan, next, arg);
 
        plan->u1.const_vp = data;
        plan->u2.s = len;
        if (len == 0)
                return set_always(conn, plan, next, arg);
 
        plan->u1.const_vp = data;
        plan->u2.s = len;
-       plan->io = do_write;
-       plan->next = next;
-       plan->next_arg = arg;
 
 
-       return plan;
+       return io_set_plan(conn, plan, do_write, next, arg);
 }
 
 static int do_read(int fd, struct io_plan *plan)
 }
 
 static int do_read(int fd, struct io_plan *plan)
@@ -201,11 +193,8 @@ struct io_plan *io_read_(struct io_conn *conn,
 
        plan->u1.cp = data;
        plan->u2.s = len;
 
        plan->u1.cp = data;
        plan->u2.s = len;
-       plan->io = do_read;
-       plan->next = next;
-       plan->next_arg = arg;
 
 
-       return plan;
+       return io_set_plan(conn, plan, do_read, next, arg);
 }
 
 static int do_read_partial(int fd, struct io_plan *plan)
 }
 
 static int do_read_partial(int fd, struct io_plan *plan)
@@ -227,8 +216,6 @@ struct io_plan *io_read_partial_(struct io_conn *conn,
 {
        struct io_plan *plan = io_get_plan(conn, IO_IN);
 
 {
        struct io_plan *plan = io_get_plan(conn, IO_IN);
 
-       assert(next);
-
        if (maxlen == 0)
                return set_always(conn, plan, next, arg);
 
        if (maxlen == 0)
                return set_always(conn, plan, next, arg);
 
@@ -236,11 +223,8 @@ struct io_plan *io_read_partial_(struct io_conn *conn,
        /* We store the max len in here temporarily. */
        *len = maxlen;
        plan->u2.vp = len;
        /* We store the max len in here temporarily. */
        *len = maxlen;
        plan->u2.vp = len;
-       plan->io = do_read_partial;
-       plan->next = next;
-       plan->next_arg = arg;
 
 
-       return plan;
+       return io_set_plan(conn, plan, do_read_partial, next, arg);
 }
 
 static int do_write_partial(int fd, struct io_plan *plan)
 }
 
 static int do_write_partial(int fd, struct io_plan *plan)
@@ -262,8 +246,6 @@ struct io_plan *io_write_partial_(struct io_conn *conn,
 {
        struct io_plan *plan = io_get_plan(conn, IO_OUT);
 
 {
        struct io_plan *plan = io_get_plan(conn, IO_OUT);
 
-       assert(next);
-
        if (maxlen == 0)
                return set_always(conn, plan, next, arg);
 
        if (maxlen == 0)
                return set_always(conn, plan, next, arg);
 
@@ -271,11 +253,8 @@ struct io_plan *io_write_partial_(struct io_conn *conn,
        /* We store the max len in here temporarily. */
        *len = maxlen;
        plan->u2.vp = len;
        /* We store the max len in here temporarily. */
        *len = maxlen;
        plan->u2.vp = len;
-       plan->io = do_write_partial;
-       plan->next = next;
-       plan->next_arg = arg;
 
 
-       return plan;
+       return io_set_plan(conn, plan, do_write_partial, next, arg);
 }
 
 static int do_connect(int fd, struct io_plan *plan)
 }
 
 static int do_connect(int fd, struct io_plan *plan)
@@ -319,11 +298,7 @@ struct io_plan *io_connect_(struct io_conn *conn, const struct addrinfo *addr,
        if (errno != EINPROGRESS)
                return io_close(conn);
 
        if (errno != EINPROGRESS)
                return io_close(conn);
 
-       plan->next = next;
-       plan->next_arg = arg;
-       plan->io = do_connect;
-
-       return plan;
+       return io_set_plan(conn, plan, do_connect, next, arg);
 }
 
 struct io_plan *io_wait_(struct io_conn *conn,
 }
 
 struct io_plan *io_wait_(struct io_conn *conn,
@@ -340,14 +315,10 @@ struct io_plan *io_wait_(struct io_conn *conn,
        else
                plan = io_get_plan(conn, IO_OUT);
 
        else
                plan = io_get_plan(conn, IO_OUT);
 
-       assert(next);
-
-       plan->next = next;
-       plan->next_arg = arg;
-       plan->u1.const_vp = wait;
        plan->status = IO_WAITING;
        plan->status = IO_WAITING;
+       plan->u1.const_vp = wait;
 
 
-       return plan;
+       return io_set_plan(conn, plan, NULL, next, arg);
 }
 
 void io_wake(const void *wait)
 }
 
 void io_wake(const void *wait)
@@ -355,11 +326,11 @@ void io_wake(const void *wait)
        backend_wake(wait);
 }
 
        backend_wake(wait);
 }
 
-static void do_plan(struct io_conn *conn, struct io_plan *plan)
+static int do_plan(struct io_conn *conn, struct io_plan *plan)
 {
        /* Someone else might have called io_close() on us. */
        if (plan->status == IO_CLOSING)
 {
        /* Someone else might have called io_close() on us. */
        if (plan->status == IO_CLOSING)
-               return;
+               return -1;
 
        /* We shouldn't have polled for this event if this wasn't true! */
        assert(plan->status == IO_POLLING);
 
        /* We shouldn't have polled for this event if this wasn't true! */
        assert(plan->status == IO_POLLING);
@@ -367,12 +338,12 @@ static void do_plan(struct io_conn *conn, struct io_plan *plan)
        switch (plan->io(conn->fd.fd, plan)) {
        case -1:
                io_close(conn);
        switch (plan->io(conn->fd.fd, plan)) {
        case -1:
                io_close(conn);
-               break;
+               return -1;
        case 0:
        case 0:
-               break;
+               return 0;
        case 1:
                next_plan(conn, plan);
        case 1:
                next_plan(conn, plan);
-               break;
+               return 1;
        default:
                /* IO should only return -1, 0 or 1 */
                abort();
        default:
                /* IO should only return -1, 0 or 1 */
                abort();
@@ -414,7 +385,7 @@ struct io_plan *io_close(struct io_conn *conn)
        conn->plan[IO_IN].u1.s = errno;
        backend_new_closing(conn);
 
        conn->plan[IO_IN].u1.s = errno;
        backend_new_closing(conn);
 
-       return &conn->plan[IO_IN];
+       return io_set_plan(conn, &conn->plan[IO_IN], NULL, NULL, NULL);
 }
 
 struct io_plan *io_close_cb(struct io_conn *conn, void *arg)
 }
 
 struct io_plan *io_close_cb(struct io_conn *conn, void *arg)
@@ -439,10 +410,85 @@ int io_conn_fd(const struct io_conn *conn)
        return conn->fd.fd;
 }
 
        return conn->fd.fd;
 }
 
-struct io_plan *io_duplex(struct io_plan *in_plan, struct io_plan *out_plan)
+void io_duplex_prepare(struct io_conn *conn)
+{
+       assert(conn->plan[IO_IN].status == IO_UNSET);
+       assert(conn->plan[IO_OUT].status == IO_UNSET);
+
+       conn->debug_saved = conn->debug;
+       conn->debug = false;
+}
+
+struct io_plan *io_duplex_(struct io_plan *in_plan, struct io_plan *out_plan)
 {
 {
+       struct io_conn *conn;
+
        /* in_plan must be conn->plan[IO_IN], out_plan must be [IO_OUT] */
        assert(out_plan == in_plan + 1);
 
        /* in_plan must be conn->plan[IO_IN], out_plan must be [IO_OUT] */
        assert(out_plan == in_plan + 1);
 
+       /* Restore debug. */
+       conn = container_of(in_plan, struct io_conn, plan[IO_IN]);
+       conn->debug = conn->debug_saved;
+
+       /* Now set the plans again, to invoke sync debug. */
+       io_set_plan(conn,
+                   out_plan, out_plan->io, out_plan->next, out_plan->next_arg);
+       io_set_plan(conn,
+                   in_plan, in_plan->io, in_plan->next, in_plan->next_arg);
+
        return out_plan + 1;
 }
        return out_plan + 1;
 }
+
+struct io_plan *io_set_plan(struct io_conn *conn, struct io_plan *plan,
+                           int (*io)(int fd, struct io_plan *plan),
+                           struct io_plan *(*next)(struct io_conn *, void *),
+                           void *next_arg)
+{
+       struct io_plan *other;
+
+       plan->io = io;
+       plan->next = next;
+       plan->next_arg = next_arg;
+       assert(plan->status == IO_CLOSING || next != NULL);
+
+       if (!conn->debug)
+               return plan;
+
+       if (io_loop_return) {
+               io_debug_complete(conn);
+               return plan;
+       }
+
+       switch (plan->status) {
+       case IO_POLLING:
+               while (do_plan(conn, plan) == 0);
+               break;
+       /* Shouldn't happen, since you said you did plan! */
+       case IO_UNSET:
+               abort();
+       case IO_ALWAYS:
+               /* If other one is ALWAYS, leave in list! */
+               if (plan == &conn->plan[IO_IN])
+                       other = &conn->plan[IO_OUT];
+               else
+                       other = &conn->plan[IO_IN];
+               if (other->status != IO_ALWAYS)
+                       remove_from_always(conn);
+               next_plan(conn, plan);
+               break;
+       case IO_WAITING:
+       case IO_CLOSING:
+               io_debug_complete(conn);
+       }
+
+       return plan;
+}
+
+void io_set_debug(struct io_conn *conn, bool debug)
+{
+       conn->debug = debug;
+}
+
+void io_debug_complete(struct io_conn *conn)
+{
+}
index 165ff6f63361d395db25a4706d21eec51b5bbb1b..1341b6f209010861958dda6de1335e4e8518e161 100644 (file)
@@ -432,11 +432,16 @@ struct io_plan *io_connect_(struct io_conn *conn, const struct addrinfo *addr,
  *
  * static struct io_plan *read_and_write(struct io_conn *conn, struct buf *b)
  * {
  *
  * static struct io_plan *read_and_write(struct io_conn *conn, struct buf *b)
  * {
- *     return io_duplex(io_read(conn, b->in, sizeof(b->in), io_close_cb, b),
- *                      io_write(conn, b->out, sizeof(b->out), io_close_cb, b));
+ *     return io_duplex(conn,
+ *                      io_read(conn, b->in, sizeof(b->in), io_close_cb, b),
+ *                      io_write(conn, b->out, sizeof(b->out), io_close_cb,b));
  * }
  */
  * }
  */
-struct io_plan *io_duplex(struct io_plan *in_plan, struct io_plan *out_plan);
+#define io_duplex(conn, in_plan, out_plan) \
+       (io_duplex_prepare(conn), io_duplex_(in_plan, out_plan))
+
+struct io_plan *io_duplex_(struct io_plan *in_plan, struct io_plan *out_plan);
+void io_duplex_prepare(struct io_conn *conn);
 
 /**
  * io_wait - leave a plan idle until something wakes us.
 
 /**
  * io_wait - leave a plan idle until something wakes us.
@@ -575,4 +580,38 @@ void *io_loop(struct timers *timers, struct list_head *expired);
  * Sometimes useful, eg for getsockname().
  */
 int io_conn_fd(const struct io_conn *conn);
  * Sometimes useful, eg for getsockname().
  */
 int io_conn_fd(const struct io_conn *conn);
+
+/**
+ * io_set_debug - set synchronous mode on a connection.
+ * @conn: the connection.
+ * @debug: whether to enable or disable debug.
+ *
+ * Once @debug is true on a connection, all I/O is done synchronously
+ * as soon as it is set, until it is unset or @conn is closed.  This
+ * makes it easy to debug what's happening with a connection, but note
+ * that other connections are starved while this is being done.
+ *
+ * See also: io_debug_complete()
+ *
+ * Example:
+ * // Dumb init function to set debug and tell conn to close.
+ * static struct io_plan *conn_init(struct io_conn *conn, const char *msg)
+ * {
+ *     io_set_debug(conn, true);
+ *     return io_close(conn);
+ * }
+ */
+void io_set_debug(struct io_conn *conn, bool debug);
+
+/**
+ * io_debug_complete - empty function called when conn is closing/waiting.
+ * @conn: the connection.
+ *
+ * This is for putting a breakpoint onto, when debugging.  It is called
+ * when a conn with io_set_debug() true can no longer be synchronous:
+ * 1) It is io_close()'d
+ * 2) It enters io_wait() (sychronous debug will resume after io_wake())
+ * 3) io_break() is called (sychronous debug will resume after io_loop())
+ */
+void io_debug_complete(struct io_conn *conn);
 #endif /* CCAN_IO_H */
 #endif /* CCAN_IO_H */
index 21a1921734f41e83d2ed836e157e4849496fb8ad..3bc2770ffb4abf8e997ad7aa6ea2e62ce6c54e86 100644 (file)
@@ -52,7 +52,51 @@ struct io_plan {
        union io_plan_arg u1, u2;
 };
 
        union io_plan_arg u1, u2;
 };
 
-/* Helper to get a conn's io_plan. */
+/**
+ * io_get_plan - get a conn's io_plan for a given direction.
+ * @conn: the connection.
+ * @dir: IO_IN or IO_OUT.
+ *
+ * This is how an io helper gets a plan to store into; you must call
+ * io_done_plan() when you've initialized it.
+ *
+ * Example:
+ * // Simple helper to read a single char.
+ * static int do_readchar(int fd, struct io_plan *plan)
+ * {
+ *     return read(fd, plan->u1.cp, 1) <= 0 ? -1 : 1;
+ * }
+ *
+ * struct io_plan *io_read_char_(struct io_conn *conn, char *in,
+ *                              struct io_plan *(*next)(struct io_conn*,void*),
+ *                              void *arg)
+ * {
+ *     struct io_plan *plan = io_get_plan(conn, IO_IN);
+ *
+ *     // Store information we need in the plan unions u1 and u2.
+ *     plan->u1.cp = in;
+ *
+ *     return io_set_plan(conn, plan, do_readchar, next, arg);
+ * }
+ */
 struct io_plan *io_get_plan(struct io_conn *conn, enum io_direction dir);
 
 struct io_plan *io_get_plan(struct io_conn *conn, enum io_direction dir);
 
+/**
+ * io_set_plan - set a conn's io_plan.
+ * @conn: the connection.
+ * @plan: the plan
+ * @io: the IO function to call when the fd is ready.
+ * @next: the next callback when @io returns 1.
+ * @next_arg: the argument to @next.
+ *
+ * If @conn has debug set, the io function will be called immediately,
+ * so it's important that this be the last thing in your function!
+ *
+ * See also:
+ *     io_get_plan()
+ */
+struct io_plan *io_set_plan(struct io_conn *conn, struct io_plan *plan,
+                           int (*io)(int fd, struct io_plan *plan),
+                           struct io_plan *(*next)(struct io_conn *, void *),
+                           void *next_arg);
 #endif /* CCAN_IO_PLAN_H */
 #endif /* CCAN_IO_PLAN_H */
index e4058766e9f6ed9661d992ed0a603af1b2ae9520..1564444bc88db780499c03a8aefa58cd08fc76c0 100644 (file)
@@ -88,17 +88,21 @@ bool add_listener(struct io_listener *l)
        return true;
 }
 
        return true;
 }
 
-void backend_new_closing(struct io_conn *conn)
+void remove_from_always(struct io_conn *conn)
 {
 {
-       /* Already on always list?  Remove it. */
-       if (conn->list) {
-               struct io_conn **p = &always;
+       struct io_conn **p = &always;
 
 
-               while (*p != conn)
-                       p = &(*p)->list;
+       while (*p != conn)
+               p = &(*p)->list;
 
 
-               *p = conn->list;
-       }
+       *p = conn->list;
+}
+
+void backend_new_closing(struct io_conn *conn)
+{
+       /* Already on always list?  Remove it. */
+       if (conn->list)
+               remove_from_always(conn);
 
        conn->list = closing;
        closing = conn;
 
        conn->list = closing;
        closing = conn;
diff --git a/ccan/io/test/run-01-start-finish-debug.c b/ccan/io/test/run-01-start-finish-debug.c
new file mode 100644 (file)
index 0000000..bc43299
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-01-start-finish.c"
index eb2c90a68b77f21bab857d250085efa94baf14d2..eb12e9488aea2eaca1dc445fb1cff6c46bddbbfc 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64001"
+#else
 #define PORT "65001"
 #endif
 static int expected_fd;
 #define PORT "65001"
 #endif
 static int expected_fd;
@@ -21,6 +23,9 @@ static void finish_ok(struct io_conn *conn, int *state)
 
 static struct io_plan *init_conn(struct io_conn *conn, int *state)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, int *state)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(*state == 0);
        (*state)++;
        expected_fd = io_conn_fd(conn);
        ok1(*state == 0);
        (*state)++;
        expected_fd = io_conn_fd(conn);
diff --git a/ccan/io/test/run-02-read-debug.c b/ccan/io/test/run-02-read-debug.c
new file mode 100644 (file)
index 0000000..eba1363
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-02-read.c"
index b43bb8bf1144af2b1bf1451f2e55d4ceba8bd1b3..e25bbbb49cc5ee8e4ad4af8856e36e62608a751e 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64002"
+#else
 #define PORT "65002"
 #endif
 
 #define PORT "65002"
 #endif
 
@@ -24,6 +26,9 @@ static void finish_ok(struct io_conn *conn, struct data *d)
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
 
        ok1(d->state == 0);
        d->state++;
 
diff --git a/ccan/io/test/run-03-readpartial-debug.c b/ccan/io/test/run-03-readpartial-debug.c
new file mode 100644 (file)
index 0000000..7c9f8c4
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-03-readpartial.c"
index 2d15c2f51c0fb9982d51d704a3411d0710ccf9d9..7c24d16e9c53bb1d6f0ffa097ae8bdf52045650f 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64003"
+#else
 #define PORT "65003"
 #endif
 
 #define PORT "65003"
 #endif
 
@@ -25,6 +27,9 @@ static void finish_ok(struct io_conn *conn, struct data *d)
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
 
        ok1(d->state == 0);
        d->state++;
 
diff --git a/ccan/io/test/run-04-writepartial-debug.c b/ccan/io/test/run-04-writepartial-debug.c
new file mode 100644 (file)
index 0000000..dd40c0c
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-04-writepartial.c"
index 011bbc894553b58699559655f6c37eeb7b6c2d1f..d3f7043f7b2764ba7bc931defdbaf7709eaa83f7 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64004"
+#else
 #define PORT "65004"
 #endif
 
 #define PORT "65004"
 #endif
 
@@ -25,6 +27,9 @@ static void finish_ok(struct io_conn *conn, struct data *d)
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
        io_set_finish(conn, finish_ok, d);
        ok1(d->state == 0);
        d->state++;
        io_set_finish(conn, finish_ok, d);
diff --git a/ccan/io/test/run-05-write-debug.c b/ccan/io/test/run-05-write-debug.c
new file mode 100644 (file)
index 0000000..5c99128
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-05-write.c"
index b17ef83ab8026ca893ede4801a4709308ac09266..41fe2949498b8f2d2166ad7810d54e29bfb351ae 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64005"
+#else
 #define PORT "65005"
 #endif
 
 #define PORT "65005"
 #endif
 
@@ -25,6 +27,9 @@ static void finish_ok(struct io_conn *conn, struct data *d)
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
        io_set_finish(conn, finish_ok, d);
        ok1(d->state == 0);
        d->state++;
        io_set_finish(conn, finish_ok, d);
index 8f3d5410d7a9058c7da1faa12470767bc79378ca..57d5e20c13ec33223300f409f35953044641abd2 100644 (file)
@@ -9,7 +9,9 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
 #include <sys/stat.h>
 #include <fcntl.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64006"
+#else
 #define PORT "65006"
 #endif
 
 #define PORT "65006"
 #endif
 
diff --git a/ccan/io/test/run-07-break-debug.c b/ccan/io/test/run-07-break-debug.c
new file mode 100644 (file)
index 0000000..94291c6
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-07-break.c"
index dd192c4d78e82e9230246708819b513734416411..d13b0f183609bc8cef34d1992eae0f068358c5be 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64007"
+#else
 #define PORT "65007"
 #endif
 
 #define PORT "65007"
 #endif
 
@@ -30,6 +32,9 @@ static void finish_ok(struct io_conn *conn, struct data *d)
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
 
        ok1(d->state == 0);
        d->state++;
 
diff --git a/ccan/io/test/run-09-connect-debug.c b/ccan/io/test/run-09-connect-debug.c
new file mode 100644 (file)
index 0000000..e7f9dde
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-09-connect.c"
index 09b33387590f78808e6a3ef67de08ffc184a7367..124b6a1f70e715f08a3014a8cee72372611ce575 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64009"
+#else
 #define PORT "65009"
 #endif
 
 #define PORT "65009"
 #endif
 
@@ -33,6 +35,9 @@ static struct io_plan *connected(struct io_conn *conn, struct data *d2)
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
        io_close_listener(l);
        ok1(d->state == 0);
        d->state++;
        io_close_listener(l);
diff --git a/ccan/io/test/run-12-bidir-debug.c b/ccan/io/test/run-12-bidir-debug.c
new file mode 100644 (file)
index 0000000..af5fd89
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-12-bidir.c"
index bddd7fbe9ed6a533d88998cb181e70a245279013..2ecc5470e7ef5a8d2ec22469bbb119a82833ba60 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64012"
+#else
 #define PORT "65012"
 #endif
 
 #define PORT "65012"
 #endif
 
@@ -34,6 +36,9 @@ static struct io_plan *rw_done(struct io_conn *conn, struct data *d)
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
 
        ok1(d->state == 0);
        d->state++;
 
@@ -42,7 +47,8 @@ static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
        memset(d->wbuf, 7, sizeof(d->wbuf));
        io_set_finish(conn, finish_ok, d);
 
        memset(d->wbuf, 7, sizeof(d->wbuf));
        io_set_finish(conn, finish_ok, d);
 
-       return io_duplex(io_read(conn, d->buf, sizeof(d->buf), rw_done, d),
+       return io_duplex(conn,
+                        io_read(conn, d->buf, sizeof(d->buf), rw_done, d),
                         io_write(conn, d->wbuf, sizeof(d->wbuf), rw_done, d));
 }
 
                         io_write(conn, d->wbuf, sizeof(d->wbuf), rw_done, d));
 }
 
diff --git a/ccan/io/test/run-14-duplex-both-read-debug.c b/ccan/io/test/run-14-duplex-both-read-debug.c
new file mode 100644 (file)
index 0000000..92bbb67
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-14-duplex-both-read.c"
index 8cf22aa16cfc6a5febe0fef0e4c2342dcb190340..ac334e7837be7d057e307b5e4aa1caa0f453878e 100644 (file)
@@ -8,7 +8,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64014"
+#else
 #define PORT "65014"
 #endif
 
 #define PORT "65014"
 #endif
 
@@ -37,12 +39,16 @@ static struct io_plan *make_duplex(struct io_conn *conn, struct data *d)
 {
        d->state++;
        /* Have duplex read the rest of the buffer. */
 {
        d->state++;
        /* Have duplex read the rest of the buffer. */
-       return io_duplex(io_read(conn, d->buf+1, sizeof(d->buf)-1, end, d),
+       return io_duplex(conn,
+                        io_read(conn, d->buf+1, sizeof(d->buf)-1, end, d),
                         io_write(conn, d->wbuf, sizeof(d->wbuf), end, d));
 }
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
                         io_write(conn, d->wbuf, sizeof(d->wbuf), end, d));
 }
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
 
        ok1(d->state == 0);
        d->state++;
 
index e0a3b05ebdf4ca19b61ccd3982f58ff9c8e40489..e4f3be6d6fffbfa997fd2f670b7ac925fbdbb5ba 100644 (file)
@@ -8,7 +8,9 @@
 #include <stdio.h>
 #include <unistd.h>
 
 #include <stdio.h>
 #include <unistd.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64015"
+#else
 #define PORT "65015"
 #endif
 
 #define PORT "65015"
 #endif
 
@@ -36,6 +38,9 @@ static struct io_plan *no_timeout(struct io_conn *conn, struct data *d)
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
 
        ok1(d->state == 0);
        d->state++;
 
diff --git a/ccan/io/test/run-16-duplex-test-debug.c b/ccan/io/test/run-16-duplex-test-debug.c
new file mode 100644 (file)
index 0000000..70ef3db
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-16-duplex-test.c"
index ea588661f7f091f2532da8fc717fb50dcf54cced..2081418334ba51b90f20dfe04edad5ea0f4053a8 100644 (file)
@@ -8,7 +8,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64016"
+#else
 #define PORT "65016"
 #endif
 
 #define PORT "65016"
 #endif
 
@@ -34,6 +36,9 @@ static struct io_plan *io_done(struct io_conn *conn, struct data *d)
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
 
        ok1(d->state == 0);
        d->state++;
 
@@ -43,7 +48,8 @@ static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 
        io_close_listener(d->l);
 
 
        io_close_listener(d->l);
 
-       return io_duplex(io_read(conn, d->buf, sizeof(d->buf), io_done, d),
+       return io_duplex(conn,
+                        io_read(conn, d->buf, sizeof(d->buf), io_done, d),
                         io_write(conn, d->wbuf, sizeof(d->wbuf), io_done, d));
 }
 
                         io_write(conn, d->wbuf, sizeof(d->wbuf), io_done, d));
 }
 
diff --git a/ccan/io/test/run-17-homemade-io-debug.c b/ccan/io/test/run-17-homemade-io-debug.c
new file mode 100644 (file)
index 0000000..e26de11
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-17-homemade-io.c"
index 1087e2509871347ad0c809abad92d40b6e7b4c11..325a7468eb4ac4b08b1ac7fc2b7abc1a565942f0 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64017"
+#else
 #define PORT "65017"
 #endif
 
 #define PORT "65017"
 #endif
 
@@ -77,15 +79,15 @@ static struct io_plan *io_read_packet(struct io_conn *conn,
        pkt->contents = NULL;
        plan->u1.vp = pkt;
        plan->u2.s = 0;
        pkt->contents = NULL;
        plan->u1.vp = pkt;
        plan->u2.s = 0;
-       plan->io = do_read_packet;
-       plan->next = cb;
-       plan->next_arg = arg;
 
 
-       return plan;
+       return io_set_plan(conn, plan, do_read_packet, cb, arg);
 }
 
 static struct io_plan *init_conn(struct io_conn *conn, struct packet *pkt)
 {
 }
 
 static struct io_plan *init_conn(struct io_conn *conn, struct packet *pkt)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(pkt->state == 0);
        pkt->state++;
 
        ok1(pkt->state == 0);
        pkt->state++;
 
diff --git a/ccan/io/test/run-18-errno-debug.c b/ccan/io/test/run-18-errno-debug.c
new file mode 100644 (file)
index 0000000..f7ffc3d
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-18-errno.c"
index c19ab375e01d081b8c4bac86c89a54c0285316b9..1bee7682bba94ea26c6b5e885e29bae6e8d50f98 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64018"
+#else
 #define PORT "65018"
 #endif
 
 #define PORT "65018"
 #endif
 
@@ -27,6 +29,9 @@ static void finish_EBADF(struct io_conn *conn, int *state)
 
 static struct io_plan *init_conn(struct io_conn *conn, int *state)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, int *state)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        if (*state == 0) {
                (*state)++;
                errno = 100;
        if (*state == 0) {
                (*state)++;
                errno = 100;
diff --git a/ccan/io/test/run-19-always-debug.c b/ccan/io/test/run-19-always-debug.c
new file mode 100644 (file)
index 0000000..f36d58e
--- /dev/null
@@ -0,0 +1,2 @@
+#define DEBUG_CONN
+#include "run-19-always.c"
index 63eb34e61fb4ec443be0c88977acaea55402f52e..7a015f28b21690ee55121a2dd3f76bbf25fca8f7 100644 (file)
@@ -6,7 +6,9 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
 #include <sys/wait.h>
 #include <stdio.h>
 
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64019"
+#else
 #define PORT "65019"
 #endif
 
 #define PORT "65019"
 #endif
 
@@ -30,6 +32,9 @@ static struct io_plan *write_buf(struct io_conn *conn, struct data *d)
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
 
 static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
 {
+#ifdef DEBUG_CONN
+       io_set_debug(conn, true);
+#endif
        ok1(d->state == 0);
        d->state++;
        io_set_finish(conn, finish_ok, d);
        ok1(d->state == 0);
        d->state++;
        io_set_finish(conn, finish_ok, d);