From: Rusty Russell Date: Thu, 29 Dec 2016 04:29:29 +0000 (+1030) Subject: io: remove io_debug support. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=96dcdfbf1a400f7cb43cf3f0761f52fd6de9ff65 io: remove io_debug support. It seemed like a good idea, but it complicates things and I never used it (since I never really trusted that the alternate paths would be equivalent). Signed-off-by: Rusty Russell --- diff --git a/ccan/io/backend.h b/ccan/io/backend.h index 3a1f12e7..aace0f2b 100644 --- a/ccan/io/backend.h +++ b/ccan/io/backend.h @@ -59,9 +59,6 @@ struct io_plan { /* One connection per client. */ struct io_conn { struct fd fd; - bool debug; - /* For duplex to save. */ - bool debug_saved; /* always and closing lists. */ struct list_node always, closing; diff --git a/ccan/io/io.c b/ccan/io/io.c index cd5557d1..83f933ac 100644 --- a/ccan/io/io.c +++ b/ccan/io/io.c @@ -94,7 +94,6 @@ struct io_conn *io_new_conn_(const tal_t *ctx, int fd, conn->finish_arg = NULL; list_node_init(&conn->always); list_node_init(&conn->closing); - conn->debug = false; if (!add_conn(conn)) return tal_free(conn); @@ -443,34 +442,12 @@ int io_conn_fd(const struct io_conn *conn) return conn->fd.fd; } -void io_duplex_prepare(struct io_conn *conn) +struct io_plan *io_duplex(struct io_conn *conn, + struct io_plan *in_plan, struct io_plan *out_plan) { - assert(conn->plan[IO_IN].status == IO_UNSET); - assert(conn->plan[IO_OUT].status == IO_UNSET); - - /* We can't sync debug until we've set both: io_wait() and io_always - * can't handle it. */ - conn->debug_saved = conn->debug; - io_set_debug(conn, false); -} - -struct io_plan *io_duplex_(struct io_plan *in_plan, struct io_plan *out_plan) -{ - struct io_conn *conn; - + assert(conn == container_of(in_plan, struct io_conn, plan[IO_IN])); /* 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]); - io_set_debug(conn, conn->debug_saved); - - /* Now set the plans again, to invoke sync debug. */ - io_set_plan(conn, IO_OUT, - out_plan->io, out_plan->next, out_plan->next_arg); - io_set_plan(conn, IO_IN, - in_plan->io, in_plan->next, in_plan->next_arg); - return out_plan + 1; } @@ -504,43 +481,5 @@ struct io_plan *io_set_plan(struct io_conn *conn, enum io_direction dir, 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 (conn->plan[!dir].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; - - /* Debugging means fds must block. */ - set_blocking(io_conn_fd(conn), debug); -} - -void io_debug_complete(struct io_conn *conn) -{ -} diff --git a/ccan/io/io.h b/ccan/io/io.h index e24beec4..fe040bce 100644 --- a/ccan/io/io.h +++ b/ccan/io/io.h @@ -454,11 +454,8 @@ struct io_plan *io_connect_(struct io_conn *conn, const struct addrinfo *addr, * io_write(conn, b->out, sizeof(b->out), io_close_cb,b)); * } */ -#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); +struct io_plan *io_duplex(struct io_conn *conn, + struct io_plan *in_plan, struct io_plan *out_plan); /** * io_halfclose - close half of an io_duplex connection. @@ -660,37 +657,4 @@ int io_conn_fd(const struct io_conn *conn); */ struct timemono (*io_time_override(struct timemono (*now)(void)))(void); -/** - * 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 */ diff --git a/ccan/io/test/run-01-start-finish-debug.c b/ccan/io/test/run-01-start-finish-debug.c deleted file mode 100644 index bc43299f..00000000 --- a/ccan/io/test/run-01-start-finish-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-01-start-finish.c" diff --git a/ccan/io/test/run-01-start-finish.c b/ccan/io/test/run-01-start-finish.c index 04952db8..5356244e 100644 --- a/ccan/io/test/run-01-start-finish.c +++ b/ccan/io/test/run-01-start-finish.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64001" -#else #define PORT "65001" -#endif static int expected_fd; static void finish_ok(struct io_conn *conn, int *state) @@ -23,9 +19,6 @@ static void finish_ok(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); diff --git a/ccan/io/test/run-02-read-debug.c b/ccan/io/test/run-02-read-debug.c deleted file mode 100644 index eba1363d..00000000 --- a/ccan/io/test/run-02-read-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-02-read.c" diff --git a/ccan/io/test/run-02-read.c b/ccan/io/test/run-02-read.c index 74cb2f02..95000b48 100644 --- a/ccan/io/test/run-02-read.c +++ b/ccan/io/test/run-02-read.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64002" -#else #define PORT "65002" -#endif struct data { int state; @@ -26,9 +22,6 @@ static void finish_ok(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++; diff --git a/ccan/io/test/run-03-readpartial-debug.c b/ccan/io/test/run-03-readpartial-debug.c deleted file mode 100644 index 7c9f8c4e..00000000 --- a/ccan/io/test/run-03-readpartial-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-03-readpartial.c" diff --git a/ccan/io/test/run-03-readpartial.c b/ccan/io/test/run-03-readpartial.c index 7c24d16e..2e2e8e16 100644 --- a/ccan/io/test/run-03-readpartial.c +++ b/ccan/io/test/run-03-readpartial.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64003" -#else #define PORT "65003" -#endif struct data { int state; @@ -27,9 +23,6 @@ static void finish_ok(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++; diff --git a/ccan/io/test/run-04-writepartial-debug.c b/ccan/io/test/run-04-writepartial-debug.c deleted file mode 100644 index dd40c0c9..00000000 --- a/ccan/io/test/run-04-writepartial-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-04-writepartial.c" diff --git a/ccan/io/test/run-04-writepartial.c b/ccan/io/test/run-04-writepartial.c index d3f7043f..947f01e5 100644 --- a/ccan/io/test/run-04-writepartial.c +++ b/ccan/io/test/run-04-writepartial.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64004" -#else #define PORT "65004" -#endif struct data { int state; @@ -27,9 +23,6 @@ static void finish_ok(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); diff --git a/ccan/io/test/run-05-write-debug.c b/ccan/io/test/run-05-write-debug.c deleted file mode 100644 index 5c991283..00000000 --- a/ccan/io/test/run-05-write-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-05-write.c" diff --git a/ccan/io/test/run-05-write.c b/ccan/io/test/run-05-write.c index 41fe2949..3b0cc724 100644 --- a/ccan/io/test/run-05-write.c +++ b/ccan/io/test/run-05-write.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64005" -#else #define PORT "65005" -#endif struct data { int state; @@ -27,9 +23,6 @@ static void finish_ok(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); diff --git a/ccan/io/test/run-06-idle.c b/ccan/io/test/run-06-idle.c index 57d5e20c..3d7c3cc3 100644 --- a/ccan/io/test/run-06-idle.c +++ b/ccan/io/test/run-06-idle.c @@ -9,11 +9,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64006" -#else #define PORT "65006" -#endif static struct io_conn *idler; diff --git a/ccan/io/test/run-07-break-debug.c b/ccan/io/test/run-07-break-debug.c deleted file mode 100644 index 94291c68..00000000 --- a/ccan/io/test/run-07-break-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-07-break.c" diff --git a/ccan/io/test/run-07-break.c b/ccan/io/test/run-07-break.c index d13b0f18..135dcbb8 100644 --- a/ccan/io/test/run-07-break.c +++ b/ccan/io/test/run-07-break.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64007" -#else #define PORT "65007" -#endif struct data { int state; @@ -32,9 +28,6 @@ static void finish_ok(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++; diff --git a/ccan/io/test/run-09-connect-debug.c b/ccan/io/test/run-09-connect-debug.c deleted file mode 100644 index e7f9ddeb..00000000 --- a/ccan/io/test/run-09-connect-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-09-connect.c" diff --git a/ccan/io/test/run-09-connect.c b/ccan/io/test/run-09-connect.c index 124b6a1f..e5f0d1f8 100644 --- a/ccan/io/test/run-09-connect.c +++ b/ccan/io/test/run-09-connect.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64009" -#else #define PORT "65009" -#endif static struct io_listener *l; static struct data *d2; @@ -35,9 +31,6 @@ 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) { -#ifdef DEBUG_CONN - io_set_debug(conn, true); -#endif 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 deleted file mode 100644 index af5fd89c..00000000 --- a/ccan/io/test/run-12-bidir-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-12-bidir.c" diff --git a/ccan/io/test/run-12-bidir.c b/ccan/io/test/run-12-bidir.c index e79acb56..77843ae7 100644 --- a/ccan/io/test/run-12-bidir.c +++ b/ccan/io/test/run-12-bidir.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64012" -#else #define PORT "65012" -#endif struct data { struct io_listener *l; @@ -42,9 +38,6 @@ static struct io_plan *w_done(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++; diff --git a/ccan/io/test/run-14-duplex-both-read-debug.c b/ccan/io/test/run-14-duplex-both-read-debug.c deleted file mode 100644 index 92bbb670..00000000 --- a/ccan/io/test/run-14-duplex-both-read-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-14-duplex-both-read.c" diff --git a/ccan/io/test/run-14-duplex-both-read.c b/ccan/io/test/run-14-duplex-both-read.c index 30c46cd5..ed77cab8 100644 --- a/ccan/io/test/run-14-duplex-both-read.c +++ b/ccan/io/test/run-14-duplex-both-read.c @@ -8,11 +8,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64014" -#else #define PORT "65014" -#endif struct data { struct io_listener *l; @@ -47,9 +43,6 @@ static struct io_plan *make_duplex(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++; diff --git a/ccan/io/test/run-15-timeout.c b/ccan/io/test/run-15-timeout.c index a4ab23ad..64741c4f 100644 --- a/ccan/io/test/run-15-timeout.c +++ b/ccan/io/test/run-15-timeout.c @@ -8,11 +8,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64015" -#else #define PORT "65015" -#endif struct data { struct timers timers; @@ -38,9 +34,6 @@ 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) { -#ifdef DEBUG_CONN - io_set_debug(conn, true); -#endif 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 deleted file mode 100644 index 70ef3db9..00000000 --- a/ccan/io/test/run-16-duplex-test-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-16-duplex-test.c" diff --git a/ccan/io/test/run-16-duplex-test.c b/ccan/io/test/run-16-duplex-test.c index 8631be45..007f4111 100644 --- a/ccan/io/test/run-16-duplex-test.c +++ b/ccan/io/test/run-16-duplex-test.c @@ -8,11 +8,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64016" -#else #define PORT "65016" -#endif struct data { struct io_listener *l; @@ -34,9 +30,6 @@ 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) { -#ifdef DEBUG_CONN - io_set_debug(conn, true); -#endif ok1(d->state == 0); d->state++; diff --git a/ccan/io/test/run-17-homemade-io-debug.c b/ccan/io/test/run-17-homemade-io-debug.c deleted file mode 100644 index e26de11c..00000000 --- a/ccan/io/test/run-17-homemade-io-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-17-homemade-io.c" diff --git a/ccan/io/test/run-17-homemade-io.c b/ccan/io/test/run-17-homemade-io.c index d104f3e9..150bcbdc 100644 --- a/ccan/io/test/run-17-homemade-io.c +++ b/ccan/io/test/run-17-homemade-io.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64017" -#else #define PORT "65017" -#endif struct packet { int state; @@ -85,9 +81,6 @@ static struct io_plan *io_read_packet(struct io_conn *conn, 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++; diff --git a/ccan/io/test/run-18-errno-debug.c b/ccan/io/test/run-18-errno-debug.c deleted file mode 100644 index f7ffc3d4..00000000 --- a/ccan/io/test/run-18-errno-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-18-errno.c" diff --git a/ccan/io/test/run-18-errno.c b/ccan/io/test/run-18-errno.c index 1bee7682..75d84cca 100644 --- a/ccan/io/test/run-18-errno.c +++ b/ccan/io/test/run-18-errno.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64018" -#else #define PORT "65018" -#endif static void finish_100(struct io_conn *conn, int *state) { @@ -29,9 +25,6 @@ static void finish_EBADF(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; diff --git a/ccan/io/test/run-19-always-debug.c b/ccan/io/test/run-19-always-debug.c deleted file mode 100644 index f36d58ed..00000000 --- a/ccan/io/test/run-19-always-debug.c +++ /dev/null @@ -1,2 +0,0 @@ -#define DEBUG_CONN -#include "run-19-always.c" diff --git a/ccan/io/test/run-19-always.c b/ccan/io/test/run-19-always.c index 7a015f28..af190a4d 100644 --- a/ccan/io/test/run-19-always.c +++ b/ccan/io/test/run-19-always.c @@ -6,11 +6,7 @@ #include #include -#ifdef DEBUG_CONN -#define PORT "64019" -#else #define PORT "65019" -#endif struct data { int state; @@ -32,9 +28,6 @@ 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) { -#ifdef DEBUG_CONN - io_set_debug(conn, true); -#endif ok1(d->state == 0); d->state++; io_set_finish(conn, finish_ok, d);