lightningd/msg_queue: support queueing/dequeueing of fds.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-03-20 06:54:14 +10:30
parent 83466b2b32
commit bde872d34c
2 changed files with 40 additions and 1 deletions

View File

@@ -5,6 +5,9 @@
#include <ccan/io/io.h>
#include <ccan/short_types/short_types.h>
/* Reserved type used to indicate we're actually passing an fd. */
#define MSG_PASS_FD 0xFFFF
struct msg_queue {
const u8 **q;
const tal_t *ctx;
@@ -12,10 +15,18 @@ struct msg_queue {
void msg_queue_init(struct msg_queue *q, const tal_t *ctx);
/* If add is taken(), freed after sending. */
void msg_enqueue(struct msg_queue *q, const u8 *add);
/* Fd is closed after sending. */
void msg_enqueue_fd(struct msg_queue *q, int fd);
/* Returns NULL if nothing to do. */
const u8 *msg_dequeue(struct msg_queue *q);
/* Returns -1 if not an fd: close after sending. */
int msg_is_fd(const u8 *msg);
#define msg_queue_wait(conn, q, next, arg) \
io_out_wait((conn), (q), (next), (arg))