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 * @fdclose: true to close fd after successful sending.
11 * @next: function to call output is done.
12 * @arg: @next argument
14 * This updates the output plan, to write out a file descriptor. This
15 * usually only works over an AF_LOCAL (ie. Unix domain) socket. Once
16 * that's sent, the @next function will be called: on an error, the
17 * finish function is called instead.
19 * Note that the I/O may actually be done immediately, and the other end
20 * of the socket must use io_recv_fd: if it does a normal read, the file
21 * descriptor will be lost.
24 * static struct io_plan *fd_to_conn(struct io_conn *conn, int fd)
26 * // Write fd, then close conn.
27 * return io_send_fd(conn, fd, false, io_close_cb, NULL);
30 #define io_send_fd(conn, fd, fdclose, next, arg) \
31 io_send_fd_((conn), (fd), (fdclose), \
32 typesafe_cb_preargs(struct io_plan *, void *, \
33 (next), (arg), struct io_conn *), \
35 struct io_plan *io_send_fd_(struct io_conn *conn,
37 struct io_plan *(*next)(struct io_conn *, void *),
41 * io_recv_fd - input plan to receive a file descriptor
42 * @conn: the connection that plan is for.
43 * @fd: a pointer to where to place to file descriptor
44 * @next: function to call once input is done.
45 * @arg: @next argument
47 * This creates a plan to receive a file descriptor, as sent by
48 * io_send_fd. Once it's all read, the @next function will be called:
49 * on an error, the finish function is called instead.
51 * Note that the I/O may actually be done immediately.
54 * static struct io_plan *read_from_conn(struct io_conn *conn, int *fdp)
56 * // Read message, then close.
57 * return io_recv_fd(conn, fdp, io_close_cb, NULL);
60 #define io_recv_fd(conn, fd, next, arg) \
61 io_recv_fd_((conn), (fd), \
62 typesafe_cb_preargs(struct io_plan *, void *, \
63 (next), (arg), struct io_conn *), \
65 struct io_plan *io_recv_fd_(struct io_conn *conn,
67 struct io_plan *(*next)(struct io_conn *, void *),
69 #endif /* CCAN_IO_FDPASS_H */