ccan/io: new module.

Designed for async I/O.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: benchmarks.

More stress test than benchmarks, but provides a beginning.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: io_duplex.

Cleaner model for I/O, with cost of complexity if you really want bidir.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: check for all idle.

It's probably a bug if we're waiting for nothing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: timer support.

Upgrade license, since timer is LGPL.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: rename io_op to io_plan.

This is a better description, since it's I/O we plan to do next.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: get rid of io_next(), pass callbacks directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: put explicit poll flags in the plan.

Weaning off enum io_state, to allow custom ones.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: remove next & finish from union.

Sure, both listener and conn need them, but for different things
(listener uses them simply to set up conn).  Putting them in the
common union was a mistake.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: use explicit IO callback functions, instead of io_state values.

Explicit callbacks are slower, but more flexible.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: make enum io_state namespace-safe.

Ready for exposure.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: replace backend_set_state with backend_wakeup()

We only use it in one place: for wakeup.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: pass struct io_plan explicitly.

This simplifies some things: in particular, we can construct an
io_plan without needing the current io_conn.

On the other hand, we need to expose the structure now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: remove conn arg from io_plan constructors.

No longer needed.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: generic init function for listening connections.

Instead of assuming they want a connection made from the new fd, hand
the fd to a callback.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: initialize connection with an explicit I/O plan.

Rather than going via a callback, which tends to just set up I/O, do
any setup before the call to io_new_conn(), then pass it the io_plan
directly.

The patch shows how much this simplifies our test code.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: remove IO_NEXT state.

It was only used for initial connections which hadn't started I/O.  Now
they are initialized with an io_plan, it can be eliminated.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: remove IO_IDLE state.

Use a NULL io pointer instead to indicate an idle connection.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: remove io_state.

Use a NULL next pointer instead to indicate a closing connection.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/io: make io functions more generic.

Pass fd and plan explicitly, so they don't need to know the definition
of struct io_conn, and return a bool instead of an enum.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>