1 /* GNU LGPL version 2 (or later) - see LICENSE file for details */
2 #ifndef CCAN_IO_FDPASS_H
3 #define CCAN_IO_FDPASS_H
4 #include <ccan/io/io.h>
7 * io_send_fd - output plan to send a file descriptor
8 * @conn: the connection that plan is for.
9 * @fd: the file descriptor to pass.
10 * @next: function to call output is done.
11 * @arg: @next argument
13 * This updates the output plan, to write out a file descriptor. This
14 * usually only works over an AF_LOCAL (ie. Unix domain) socket. Once
15 * that's sent, the @next function will be called: on an error, the
16 * finish function is called instead.
18 * Note that the I/O may actually be done immediately, and the other end
19 * of the socket must use io_recv_fd: if it does a normal read, the file
20 * descriptor will be lost.
23 * static struct io_plan *fd_to_conn(struct io_conn *conn, int fd)
25 * // Write fd, then close.
26 * return io_send_fd(conn, fd, io_close_cb, NULL);
29 #define io_send_fd(conn, fd, next, arg) \
30 io_send_fd_((conn), (fd), \
31 typesafe_cb_preargs(struct io_plan *, void *, \
32 (next), (arg), struct io_conn *), \
34 struct io_plan *io_send_fd_(struct io_conn *conn,
36 struct io_plan *(*next)(struct io_conn *, void *),
40 * io_recv_fd - input plan to receive a file descriptor
41 * @conn: the connection that plan is for.
42 * @fd: a pointer to where to place to file descriptor
43 * @next: function to call once input is done.
44 * @arg: @next argument
46 * This creates a plan to receive a file descriptor, as sent by
47 * io_send_fd. Once it's all read, the @next function will be called:
48 * on an error, the finish function is called instead.
50 * Note that the I/O may actually be done immediately.
53 * static struct io_plan *read_from_conn(struct io_conn *conn, int *fdp)
55 * // Read message, then close.
56 * return io_recv_fd(conn, fdp, io_close_cb, NULL);
59 #define io_recv_fd(conn, fd, next, arg) \
60 io_recv_fd_((conn), (fd), \
61 typesafe_cb_preargs(struct io_plan *, void *, \
62 (next), (arg), struct io_conn *), \
64 struct io_plan *io_recv_fd_(struct io_conn *conn,
66 struct io_plan *(*next)(struct io_conn *, void *),
68 #endif /* CCAN_IO_FDPASS_H */