Browse Source

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 <rusty@rustcorp.com.au>
Rusty Russell 9 years ago
parent
commit
96dcdfbf1a

+ 0 - 3
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;

+ 3 - 64
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)
-{
-}

+ 2 - 38
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 */

+ 0 - 2
ccan/io/test/run-01-start-finish-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-01-start-finish.c"

+ 0 - 7
ccan/io/test/run-01-start-finish.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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);

+ 0 - 2
ccan/io/test/run-02-read-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-02-read.c"

+ 0 - 7
ccan/io/test/run-02-read.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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++;
 

+ 0 - 2
ccan/io/test/run-03-readpartial-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-03-readpartial.c"

+ 0 - 7
ccan/io/test/run-03-readpartial.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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++;
 

+ 0 - 2
ccan/io/test/run-04-writepartial-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-04-writepartial.c"

+ 0 - 7
ccan/io/test/run-04-writepartial.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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);

+ 0 - 2
ccan/io/test/run-05-write-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-05-write.c"

+ 0 - 7
ccan/io/test/run-05-write.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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);

+ 0 - 4
ccan/io/test/run-06-idle.c

@@ -9,11 +9,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-#ifdef DEBUG_CONN
-#define PORT "64006"
-#else
 #define PORT "65006"
-#endif
 
 static struct io_conn *idler;
 

+ 0 - 2
ccan/io/test/run-07-break-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-07-break.c"

+ 0 - 7
ccan/io/test/run-07-break.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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++;
 

+ 0 - 2
ccan/io/test/run-09-connect-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-09-connect.c"

+ 0 - 7
ccan/io/test/run-09-connect.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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);

+ 0 - 2
ccan/io/test/run-12-bidir-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-12-bidir.c"

+ 0 - 7
ccan/io/test/run-12-bidir.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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++;
 

+ 0 - 2
ccan/io/test/run-14-duplex-both-read-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-14-duplex-both-read.c"

+ 0 - 7
ccan/io/test/run-14-duplex-both-read.c

@@ -8,11 +8,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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++;
 

+ 0 - 7
ccan/io/test/run-15-timeout.c

@@ -8,11 +8,7 @@
 #include <stdio.h>
 #include <unistd.h>
 
-#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++;
 

+ 0 - 2
ccan/io/test/run-16-duplex-test-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-16-duplex-test.c"

+ 0 - 7
ccan/io/test/run-16-duplex-test.c

@@ -8,11 +8,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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++;
 

+ 0 - 2
ccan/io/test/run-17-homemade-io-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-17-homemade-io.c"

+ 0 - 7
ccan/io/test/run-17-homemade-io.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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++;
 

+ 0 - 2
ccan/io/test/run-18-errno-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-18-errno.c"

+ 0 - 7
ccan/io/test/run-18-errno.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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;

+ 0 - 2
ccan/io/test/run-19-always-debug.c

@@ -1,2 +0,0 @@
-#define DEBUG_CONN
-#include "run-19-always.c"

+ 0 - 7
ccan/io/test/run-19-always.c

@@ -6,11 +6,7 @@
 #include <sys/wait.h>
 #include <stdio.h>
 
-#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);