#include <sys/wait.h>
#include <stdio.h>
-#ifndef PORT
+#ifdef DEBUG_CONN
+#define PORT "64018"
+#else
#define PORT "65018"
#endif
ok1(errno == EBADF);
ok1(*state == 3);
(*state)++;
- io_break(state + 1, io_close());
+ io_break(state + 1);
}
-static void init_conn(int fd, 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;
- io_set_finish(io_new_conn(fd, io_close()), finish_100, state);
+ io_set_finish(conn, finish_100, state);
+ return io_close(conn);
} else {
ok1(*state == 2);
(*state)++;
- close(fd);
+ close(io_conn_fd(conn));
errno = 0;
- io_set_finish(io_new_conn(fd, io_read(state, 1,
- io_close_cb, NULL)),
- finish_EBADF, state);
+ io_set_finish(conn, finish_EBADF, state);
+
+ return io_read(conn, state, 1, io_close_cb, NULL);
}
}
plan_tests(12);
fd = make_listen_fd(PORT, &addrinfo);
ok1(fd >= 0);
- l = io_new_listener(fd, init_conn, &state);
+ l = io_new_listener(NULL, fd, init_conn, &state);
ok1(l);
fflush(stdout);
if (!fork()) {
exit(0);
}
freeaddrinfo(addrinfo);
- ok1(io_loop() == &state + 1);
+ ok1(io_loop(NULL, NULL) == &state + 1);
ok1(state == 4);
io_close_listener(l);
ok1(wait(&state));