2017-03-10 11:44:40 +01:00
|
|
|
/* Helper for simple message queues. */
|
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_MSG_QUEUE_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_MSG_QUEUE_H
|
|
|
|
#include "config.h"
|
|
|
|
#include <ccan/io/io.h>
|
|
|
|
#include <ccan/short_types/short_types.h>
|
|
|
|
|
2017-03-19 21:24:14 +01:00
|
|
|
/* Reserved type used to indicate we're actually passing an fd. */
|
|
|
|
#define MSG_PASS_FD 0xFFFF
|
|
|
|
|
2017-03-10 11:44:40 +01:00
|
|
|
struct msg_queue {
|
|
|
|
const u8 **q;
|
2017-03-13 17:24:05 +01:00
|
|
|
const tal_t *ctx;
|
2017-03-10 11:44:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void msg_queue_init(struct msg_queue *q, const tal_t *ctx);
|
|
|
|
|
2017-04-12 18:10:10 +02:00
|
|
|
/* If add is taken(), freed after sending. msg_wake() implied. */
|
2017-03-10 11:44:40 +01:00
|
|
|
void msg_enqueue(struct msg_queue *q, const u8 *add);
|
|
|
|
|
2017-04-12 18:10:10 +02:00
|
|
|
/* Fd is closed after sending. msg_wake() implied. */
|
2017-03-19 21:24:14 +01:00
|
|
|
void msg_enqueue_fd(struct msg_queue *q, int fd);
|
|
|
|
|
2017-04-12 18:10:10 +02:00
|
|
|
/* Explicitly wake up a msg_queue_wait */
|
|
|
|
void msg_wake(const struct msg_queue *q);
|
|
|
|
|
2017-03-19 21:24:14 +01:00
|
|
|
/* Returns NULL if nothing to do. */
|
2017-03-10 11:44:40 +01:00
|
|
|
const u8 *msg_dequeue(struct msg_queue *q);
|
|
|
|
|
2017-03-19 21:24:14 +01:00
|
|
|
/* Returns -1 if not an fd: close after sending. */
|
2017-03-19 21:32:44 +01:00
|
|
|
int msg_extract_fd(const u8 *msg);
|
2017-03-19 21:24:14 +01:00
|
|
|
|
2017-03-10 11:44:40 +01:00
|
|
|
#define msg_queue_wait(conn, q, next, arg) \
|
|
|
|
io_out_wait((conn), (q), (next), (arg))
|
|
|
|
|
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_MSG_QUEUE_H */
|