Commit 96dcdfbf authored by Rusty Russell's avatar Rusty Russell

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: default avatarRusty Russell <rusty@rustcorp.com.au>
parent ba89419a
...@@ -59,9 +59,6 @@ struct io_plan { ...@@ -59,9 +59,6 @@ struct io_plan {
/* One connection per client. */ /* One connection per client. */
struct io_conn { struct io_conn {
struct fd fd; struct fd fd;
bool debug;
/* For duplex to save. */
bool debug_saved;
/* always and closing lists. */ /* always and closing lists. */
struct list_node always, closing; struct list_node always, closing;
......
...@@ -94,7 +94,6 @@ struct io_conn *io_new_conn_(const tal_t *ctx, int fd, ...@@ -94,7 +94,6 @@ struct io_conn *io_new_conn_(const tal_t *ctx, int fd,
conn->finish_arg = NULL; conn->finish_arg = NULL;
list_node_init(&conn->always); list_node_init(&conn->always);
list_node_init(&conn->closing); list_node_init(&conn->closing);
conn->debug = false;
if (!add_conn(conn)) if (!add_conn(conn))
return tal_free(conn); return tal_free(conn);
...@@ -443,34 +442,12 @@ int io_conn_fd(const struct io_conn *conn) ...@@ -443,34 +442,12 @@ int io_conn_fd(const struct io_conn *conn)
return conn->fd.fd; 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 == container_of(in_plan, struct io_conn, plan[IO_IN]));
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;
/* in_plan must be conn->plan[IO_IN], out_plan must be [IO_OUT] */ /* in_plan must be conn->plan[IO_IN], out_plan must be [IO_OUT] */
assert(out_plan == in_plan + 1); 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; return out_plan + 1;
} }
...@@ -504,43 +481,5 @@ struct io_plan *io_set_plan(struct io_conn *conn, enum io_direction dir, ...@@ -504,43 +481,5 @@ struct io_plan *io_set_plan(struct io_conn *conn, enum io_direction dir,
plan->next_arg = next_arg; plan->next_arg = next_arg;
assert(plan->status == IO_CLOSING || next != NULL); 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; 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)
{
}
...@@ -454,11 +454,8 @@ struct io_plan *io_connect_(struct io_conn *conn, const struct addrinfo *addr, ...@@ -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)); * io_write(conn, b->out, sizeof(b->out), io_close_cb,b));
* } * }
*/ */
#define io_duplex(conn, in_plan, out_plan) \ struct io_plan *io_duplex(struct io_conn *conn,
(io_duplex_prepare(conn), io_duplex_(in_plan, out_plan)) struct io_plan *in_plan, struct io_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_halfclose - close half of an io_duplex connection. * io_halfclose - close half of an io_duplex connection.
...@@ -660,37 +657,4 @@ int io_conn_fd(const struct io_conn *conn); ...@@ -660,37 +657,4 @@ int io_conn_fd(const struct io_conn *conn);
*/ */
struct timemono (*io_time_override(struct timemono (*now)(void)))(void); 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 */ #endif /* CCAN_IO_H */
#define DEBUG_CONN
#include "run-01-start-finish.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64001"
#else
#define PORT "65001" #define PORT "65001"
#endif
static int expected_fd; static int expected_fd;
static void finish_ok(struct io_conn *conn, int *state) static void finish_ok(struct io_conn *conn, int *state)
...@@ -23,9 +19,6 @@ 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) static struct io_plan *init_conn(struct io_conn *conn, int *state)
{ {
#ifdef DEBUG_CONN
io_set_debug(conn, true);
#endif
ok1(*state == 0); ok1(*state == 0);
(*state)++; (*state)++;
expected_fd = io_conn_fd(conn); expected_fd = io_conn_fd(conn);
......
#define DEBUG_CONN
#include "run-02-read.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64002"
#else
#define PORT "65002" #define PORT "65002"
#endif
struct data { struct data {
int state; int state;
...@@ -26,9 +22,6 @@ static void finish_ok(struct io_conn *conn, struct data *d) ...@@ -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) 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); ok1(d->state == 0);
d->state++; d->state++;
......
#define DEBUG_CONN
#include "run-03-readpartial.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64003"
#else
#define PORT "65003" #define PORT "65003"
#endif
struct data { struct data {
int state; int state;
...@@ -27,9 +23,6 @@ static void finish_ok(struct io_conn *conn, struct data *d) ...@@ -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) 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); ok1(d->state == 0);
d->state++; d->state++;
......
#define DEBUG_CONN
#include "run-04-writepartial.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64004"
#else
#define PORT "65004" #define PORT "65004"
#endif
struct data { struct data {
int state; int state;
...@@ -27,9 +23,6 @@ static void finish_ok(struct io_conn *conn, struct data *d) ...@@ -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) 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); ok1(d->state == 0);
d->state++; d->state++;
io_set_finish(conn, finish_ok, d); io_set_finish(conn, finish_ok, d);
......
#define DEBUG_CONN
#include "run-05-write.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64005"
#else
#define PORT "65005" #define PORT "65005"
#endif
struct data { struct data {
int state; int state;
...@@ -27,9 +23,6 @@ static void finish_ok(struct io_conn *conn, struct data *d) ...@@ -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) 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); ok1(d->state == 0);
d->state++; d->state++;
io_set_finish(conn, finish_ok, d); io_set_finish(conn, finish_ok, d);
......
...@@ -9,11 +9,7 @@ ...@@ -9,11 +9,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef DEBUG_CONN
#define PORT "64006"
#else
#define PORT "65006" #define PORT "65006"
#endif
static struct io_conn *idler; static struct io_conn *idler;
......
#define DEBUG_CONN
#include "run-07-break.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64007"
#else
#define PORT "65007" #define PORT "65007"
#endif
struct data { struct data {
int state; int state;
...@@ -32,9 +28,6 @@ static void finish_ok(struct io_conn *conn, struct data *d) ...@@ -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) 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); ok1(d->state == 0);
d->state++; d->state++;
......
#define DEBUG_CONN
#include "run-09-connect.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64009"
#else
#define PORT "65009" #define PORT "65009"
#endif
static struct io_listener *l; static struct io_listener *l;
static struct data *d2; static struct data *d2;
...@@ -35,9 +31,6 @@ static struct io_plan *connected(struct io_conn *conn, 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) 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); ok1(d->state == 0);
d->state++; d->state++;
io_close_listener(l); io_close_listener(l);
......
#define DEBUG_CONN
#include "run-12-bidir.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64012"
#else
#define PORT "65012" #define PORT "65012"
#endif
struct data { struct data {
struct io_listener *l; struct io_listener *l;
...@@ -42,9 +38,6 @@ static struct io_plan *w_done(struct io_conn *conn, struct data *d) ...@@ -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) 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); ok1(d->state == 0);
d->state++; d->state++;
......
#define DEBUG_CONN
#include "run-14-duplex-both-read.c"
...@@ -8,11 +8,7 @@ ...@@ -8,11 +8,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64014"
#else
#define PORT "65014" #define PORT "65014"
#endif
struct data { struct data {
struct io_listener *l; struct io_listener *l;
...@@ -47,9 +43,6 @@ static struct io_plan *make_duplex(struct io_conn *conn, struct data *d) ...@@ -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) 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); ok1(d->state == 0);
d->state++; d->state++;
......
...@@ -8,11 +8,7 @@ ...@@ -8,11 +8,7 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#ifdef DEBUG_CONN
#define PORT "64015"
#else
#define PORT "65015" #define PORT "65015"
#endif
struct data { struct data {
struct timers timers; struct timers timers;
...@@ -38,9 +34,6 @@ static struct io_plan *no_timeout(struct io_conn *conn, struct data *d) ...@@ -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) 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); ok1(d->state == 0);
d->state++; d->state++;
......
#define DEBUG_CONN
#include "run-16-duplex-test.c"
...@@ -8,11 +8,7 @@ ...@@ -8,11 +8,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64016"
#else
#define PORT "65016" #define PORT "65016"
#endif
struct data { struct data {
struct io_listener *l; struct io_listener *l;
...@@ -34,9 +30,6 @@ static struct io_plan *io_done(struct io_conn *conn, struct data *d) ...@@ -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) 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); ok1(d->state == 0);
d->state++; d->state++;
......
#define DEBUG_CONN
#include "run-17-homemade-io.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64017"
#else
#define PORT "65017" #define PORT "65017"
#endif
struct packet { struct packet {
int state; int state;
...@@ -85,9 +81,6 @@ static struct io_plan *io_read_packet(struct io_conn *conn, ...@@ -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) 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); ok1(pkt->state == 0);
pkt->state++; pkt->state++;
......
#define DEBUG_CONN
#include "run-18-errno.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64018"
#else
#define PORT "65018" #define PORT "65018"
#endif
static void finish_100(struct io_conn *conn, int *state) static void finish_100(struct io_conn *conn, int *state)
{ {
...@@ -29,9 +25,6 @@ static void finish_EBADF(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) static struct io_plan *init_conn(struct io_conn *conn, int *state)
{ {
#ifdef DEBUG_CONN
io_set_debug(conn, true);
#endif
if (*state == 0) { if (*state == 0) {
(*state)++; (*state)++;
errno = 100; errno = 100;
......
#define DEBUG_CONN
#include "run-19-always.c"
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <stdio.h> #include <stdio.h>
#ifdef DEBUG_CONN
#define PORT "64019"
#else
#define PORT "65019" #define PORT "65019"
#endif
struct data { struct data {
int state; int state;
...@@ -32,9 +28,6 @@ static struct io_plan *write_buf(struct io_conn *conn, struct data *d) ...@@ -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) 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); ok1(d->state == 0);
d->state++; d->state++;
io_set_finish(conn, finish_ok, d); io_set_finish(conn, finish_ok, d);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment