current->plan = plan;
backend_plan_changed(current);
+ /* If it closed, close duplex. */
+ if (!current->plan.next && current->duplex) {
+ current->duplex->plan = io_close_();
+ backend_plan_changed(current->duplex);
+ }
+
/* Call back into the loop immediately. */
io_loop_return = do_io_loop(&ready);
backend_plan_changed(conn);
}
set_current(NULL);
+
+ /* If it closed, close duplex. */
+ if (!conn->plan.next && conn->duplex) {
+ set_current(conn->duplex);
+ conn->duplex->plan = io_close();
+ backend_plan_changed(conn->duplex);
+ set_current(NULL);
+ }
}
/* Close the connection, we're done. */
* to have two connections for the same fd, and use one for read
* operations and one for write.
*
- * You must io_close() both of them to close the fd.
+ * Returning io_close() on one will close both fds!
*
* Example:
* static void setup_read_write(int fd,
static struct io_plan write_done(struct io_conn *conn, struct data *d)
{
d->state++;
- return io_close();
+ return io_idle();
}
static void init_conn(int fd, struct data *d)
#endif
/* Returns member, or NULL if at end of list. */
-static inline void *list_entry_or_null(struct list_head *h,
- struct list_node *n,
+static inline void *list_entry_or_null(const struct list_head *h,
+ const struct list_node *n,
size_t off)
{
if (n == &h->n)
{
struct parent parent;
struct child c1, c2, c3;
+ const struct parent *p;
+ const struct child *c;
- plan_tests(12);
+ plan_tests(20);
parent.num_children = 0;
list_head_init(&parent.children);
ok1(list_prev(&parent.children, &c2, list) == &c1);
ok1(list_next(&parent.children, &c3, list) == NULL);
ok1(list_prev(&parent.children, &c3, list) == &c2);
+
+ /* Const variants */
+ p = &parent;
+ c = &c2;
+ ok1(list_next(&p->children, &c1, list) == &c2);
+ ok1(list_prev(&p->children, &c1, list) == NULL);
+ ok1(list_next(&p->children, c, list) == &c3);
+ ok1(list_prev(&p->children, c, list) == &c1);
+ ok1(list_next(&parent.children, c, list) == &c3);
+ ok1(list_prev(&parent.children, c, list) == &c1);
+ ok1(list_next(&p->children, &c3, list) == NULL);
+ ok1(list_prev(&p->children, &c3, list) == &c2);
+
return exit_status();
}