forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
daemon_conn.h
59 lines (51 loc) · 1.8 KB
/
daemon_conn.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef LIGHTNING_COMMON_DAEMON_CONN_H
#define LIGHTNING_COMMON_DAEMON_CONN_H
#include "config.h"
#include <ccan/io/io.h>
#include <ccan/short_types/short_types.h>
#include <common/msg_queue.h>
/**
* daemon_conn_new - Allocate a new daemon connection
*
* @ctx: context to allocate the daemon_conn's conn from
* @fd: socket file descriptor to wrap
* @recv: callback function to be called upon receiving a message
* @outq_empty: callback function to be called when queue is empty: returns
* true if it added something to the queue. Can be NULL.
*/
#define daemon_conn_new(ctx, fd, recv, outq_empty, arg) \
daemon_conn_new_((ctx), (fd), \
typesafe_cb_preargs(struct io_plan *, void *, \
(recv), (arg), \
struct io_conn *, \
const u8 *), \
typesafe_cb(void, void *, (outq_empty), (arg)), \
arg)
struct daemon_conn *daemon_conn_new_(const tal_t *ctx, int fd,
struct io_plan *(*recv)(struct io_conn *,
const u8 *,
void *),
void (*outq_empty)(void *),
void *arg);
/**
* daemon_conn_send - Enqueue an outgoing message to be sent
*/
void daemon_conn_send(struct daemon_conn *dc, const u8 *msg);
/**
* daemon_conn_wake - Wake queue (fires msg_queue_cleared_cb if queue empty)
*/
void daemon_conn_wake(struct daemon_conn *dc);
/**
* daemon_conn_send_fd - Enqueue a file descriptor to be sent (closed after)
*/
void daemon_conn_send_fd(struct daemon_conn *dc, int fd);
/**
* daemon_conn_read_next - Read the next message
*/
struct io_plan *daemon_conn_read_next(struct io_conn *conn,
struct daemon_conn *dc);
/**
* daemon_conn_sync_flush - Flush connection by sending all messages now..
*/
bool daemon_conn_sync_flush(struct daemon_conn *dc);
#endif /* LIGHTNING_COMMON_DAEMON_CONN_H */