/* 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;
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);
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;
}
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)
-{
-}
* 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.
*/
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 */
+++ /dev/null
-#define DEBUG_CONN
-#include "run-01-start-finish.c"
#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)
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);
+++ /dev/null
-#define DEBUG_CONN
-#include "run-02-read.c"
#include <sys/wait.h>
#include <stdio.h>
-#ifdef DEBUG_CONN
-#define PORT "64002"
-#else
#define PORT "65002"
-#endif
struct data {
int state;
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++;
+++ /dev/null
-#define DEBUG_CONN
-#include "run-03-readpartial.c"
#include <sys/wait.h>
#include <stdio.h>
-#ifdef DEBUG_CONN
-#define PORT "64003"
-#else
#define PORT "65003"
-#endif
struct data {
int state;
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++;
+++ /dev/null
-#define DEBUG_CONN
-#include "run-04-writepartial.c"
#include <sys/wait.h>
#include <stdio.h>
-#ifdef DEBUG_CONN
-#define PORT "64004"
-#else
#define PORT "65004"
-#endif
struct data {
int state;
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);
+++ /dev/null
-#define DEBUG_CONN
-#include "run-05-write.c"
#include <sys/wait.h>
#include <stdio.h>
-#ifdef DEBUG_CONN
-#define PORT "64005"
-#else
#define PORT "65005"
-#endif
struct data {
int state;
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);
#include <sys/stat.h>
#include <fcntl.h>
-#ifdef DEBUG_CONN
-#define PORT "64006"
-#else
#define PORT "65006"
-#endif
static struct io_conn *idler;
+++ /dev/null
-#define DEBUG_CONN
-#include "run-07-break.c"
#include <sys/wait.h>
#include <stdio.h>
-#ifdef DEBUG_CONN
-#define PORT "64007"
-#else
#define PORT "65007"
-#endif
struct data {
int state;
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++;
+++ /dev/null
-#define DEBUG_CONN
-#include "run-09-connect.c"
#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;
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);
+++ /dev/null
-#define DEBUG_CONN
-#include "run-12-bidir.c"
#include <sys/wait.h>
#include <stdio.h>
-#ifdef DEBUG_CONN
-#define PORT "64012"
-#else
#define PORT "65012"
-#endif
struct data {
struct io_listener *l;
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++;
+++ /dev/null
-#define DEBUG_CONN
-#include "run-14-duplex-both-read.c"
#include <sys/wait.h>
#include <stdio.h>
-#ifdef DEBUG_CONN
-#define PORT "64014"
-#else
#define PORT "65014"
-#endif
struct data {
struct io_listener *l;
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++;
#include <stdio.h>
#include <unistd.h>
-#ifdef DEBUG_CONN
-#define PORT "64015"
-#else
#define PORT "65015"
-#endif
struct data {
struct timers timers;
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++;
+++ /dev/null
-#define DEBUG_CONN
-#include "run-16-duplex-test.c"
#include <sys/wait.h>
#include <stdio.h>
-#ifdef DEBUG_CONN
-#define PORT "64016"
-#else
#define PORT "65016"
-#endif
struct data {
struct io_listener *l;
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++;
+++ /dev/null
-#define DEBUG_CONN
-#include "run-17-homemade-io.c"
#include <sys/wait.h>
#include <stdio.h>
-#ifdef DEBUG_CONN
-#define PORT "64017"
-#else
#define PORT "65017"
-#endif
struct packet {
int state;
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++;
+++ /dev/null
-#define DEBUG_CONN
-#include "run-18-errno.c"
#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)
{
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;
+++ /dev/null
-#define DEBUG_CONN
-#include "run-19-always.c"
#include <sys/wait.h>
#include <stdio.h>
-#ifdef DEBUG_CONN
-#define PORT "64019"
-#else
#define PORT "65019"
-#endif
struct data {
int state;
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);