Useful for getsockname().
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
+int io_conn_fd(const struct io_conn *conn)
+{
+ return conn->fd.fd;
+}
+
void io_set_alloc(void *(*allocfn)(size_t size),
void *(*reallocfn)(void *ptr, size_t size),
void (*freefn)(void *ptr))
void io_set_alloc(void *(*allocfn)(size_t size),
void *(*reallocfn)(void *ptr, size_t size),
void (*freefn)(void *ptr))
+/**
+ * io_conn_fd - get the fd from a connection.
+ * @conn: the connection.
+ *
+ * Sometimes useful, eg for getsockname().
+ */
+int io_conn_fd(const struct io_conn *conn);
+
/**
* io_set_alloc - set alloc/realloc/free function for io to use.
* @allocfn: allocator function
/**
* io_set_alloc - set alloc/realloc/free function for io to use.
* @allocfn: allocator function
#ifndef PORT
#define PORT "65001"
#endif
#ifndef PORT
#define PORT "65001"
#endif
static void finish_ok(struct io_conn *conn, int *state)
{
ok1(*state == 1);
static void finish_ok(struct io_conn *conn, int *state)
{
ok1(*state == 1);
+ ok1(io_conn_fd(conn) == expected_fd);
(*state)++;
io_break(state + 1, io_idle());
}
(*state)++;
io_break(state + 1, io_idle());
}
{
ok1(*state == 0);
(*state)++;
{
ok1(*state == 0);
(*state)++;
io_set_finish(io_new_conn(fd, io_close()), finish_ok, state);
}
io_set_finish(io_new_conn(fd, io_close()), finish_ok, state);
}
int fd;
/* This is how many tests you plan to run */
int fd;
/* This is how many tests you plan to run */
fd = make_listen_fd(PORT, &addrinfo);
ok1(fd >= 0);
l = io_new_listener(fd, init_conn, &state);
fd = make_listen_fd(PORT, &addrinfo);
ok1(fd >= 0);
l = io_new_listener(fd, init_conn, &state);