|
|
@ -1,4 +1,7 @@ |
|
|
|
#include <assert.h> |
|
|
|
#include <ccan/take/take.h> |
|
|
|
#include <lightningd/msg_queue.h> |
|
|
|
#include <wire/wire.h> |
|
|
|
|
|
|
|
void msg_queue_init(struct msg_queue *q, const tal_t *ctx) |
|
|
|
{ |
|
|
@ -6,7 +9,7 @@ void msg_queue_init(struct msg_queue *q, const tal_t *ctx) |
|
|
|
q->ctx = ctx; |
|
|
|
} |
|
|
|
|
|
|
|
void msg_enqueue(struct msg_queue *q, const u8 *add) |
|
|
|
static void do_enqueue(struct msg_queue *q, const u8 *add) |
|
|
|
{ |
|
|
|
size_t n = tal_count(q->q); |
|
|
|
tal_resize(&q->q, n+1); |
|
|
@ -16,6 +19,20 @@ void msg_enqueue(struct msg_queue *q, const u8 *add) |
|
|
|
io_wake(q); |
|
|
|
} |
|
|
|
|
|
|
|
void msg_enqueue(struct msg_queue *q, const u8 *add) |
|
|
|
{ |
|
|
|
assert(fromwire_peektype(add) != MSG_PASS_FD); |
|
|
|
do_enqueue(q, add); |
|
|
|
} |
|
|
|
|
|
|
|
void msg_enqueue_fd(struct msg_queue *q, int fd) |
|
|
|
{ |
|
|
|
u8 *fdmsg = tal_arr(q->ctx, u8, 0); |
|
|
|
towire_u16(&fdmsg, MSG_PASS_FD); |
|
|
|
towire_u32(&fdmsg, fd); |
|
|
|
do_enqueue(q, take(fdmsg)); |
|
|
|
} |
|
|
|
|
|
|
|
const u8 *msg_dequeue(struct msg_queue *q) |
|
|
|
{ |
|
|
|
size_t n = tal_count(q->q); |
|
|
@ -29,3 +46,14 @@ const u8 *msg_dequeue(struct msg_queue *q) |
|
|
|
tal_resize(&q->q, n-1); |
|
|
|
return msg; |
|
|
|
} |
|
|
|
|
|
|
|
int msg_is_fd(const u8 *msg) |
|
|
|
{ |
|
|
|
const u8 *p = msg + sizeof(u16); |
|
|
|
size_t len = tal_count(msg) - sizeof(u16); |
|
|
|
|
|
|
|
if (fromwire_peektype(msg) != MSG_PASS_FD) |
|
|
|
return -1; |
|
|
|
|
|
|
|
return fromwire_u32(&p, &len); |
|
|
|
} |
|
|
|