2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_COMMON_DAEMON_CONN_H
|
|
|
|
#define LIGHTNING_COMMON_DAEMON_CONN_H
|
2017-03-10 13:37:20 +01:00
|
|
|
|
|
|
|
#include "config.h"
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/msg_queue.h>
|
2017-03-10 13:37:20 +01:00
|
|
|
|
|
|
|
/**
|
2018-10-25 01:43:05 +02:00
|
|
|
* daemon_conn_new - Allocate a new daemon connection
|
2017-03-10 13:37:20 +01:00
|
|
|
*
|
2018-10-25 01:43:05 +02:00
|
|
|
* @ctx: context to allocate the daemon_conn's conn from
|
2017-03-10 13:37:20 +01:00
|
|
|
* @fd: socket file descriptor to wrap
|
2018-10-25 01:43:05 +02:00
|
|
|
* @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.
|
2017-12-06 07:13:56 +01:00
|
|
|
*/
|
2018-10-25 01:43:05 +02:00
|
|
|
#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 *), \
|
2018-11-13 05:03:50 +01:00
|
|
|
typesafe_cb(void, void *, (outq_empty), (arg)), \
|
2018-10-25 01:43:05 +02:00
|
|
|
arg)
|
|
|
|
|
|
|
|
struct daemon_conn *daemon_conn_new_(const tal_t *ctx, int fd,
|
|
|
|
struct io_plan *(*recv)(struct io_conn *,
|
|
|
|
const u8 *,
|
|
|
|
void *),
|
2018-11-13 05:03:50 +01:00
|
|
|
void (*outq_empty)(void *),
|
2018-10-25 01:43:05 +02:00
|
|
|
void *arg);
|
2017-12-06 07:13:56 +01:00
|
|
|
|
2017-03-10 13:37:20 +01:00
|
|
|
/**
|
|
|
|
* daemon_conn_send - Enqueue an outgoing message to be sent
|
|
|
|
*/
|
2017-03-17 19:45:52 +01:00
|
|
|
void daemon_conn_send(struct daemon_conn *dc, const u8 *msg);
|
2017-03-10 13:37:20 +01:00
|
|
|
|
2018-07-24 08:18:40 +02:00
|
|
|
/**
|
|
|
|
* daemon_conn_wake - Wake queue (fires msg_queue_cleared_cb if queue empty)
|
|
|
|
*/
|
|
|
|
void daemon_conn_wake(struct daemon_conn *dc);
|
|
|
|
|
2017-03-19 21:24:14 +01:00
|
|
|
/**
|
|
|
|
* daemon_conn_send_fd - Enqueue a file descriptor to be sent (closed after)
|
|
|
|
*/
|
|
|
|
void daemon_conn_send_fd(struct daemon_conn *dc, int fd);
|
|
|
|
|
2017-03-10 13:37:20 +01:00
|
|
|
/**
|
|
|
|
* daemon_conn_read_next - Read the next message
|
|
|
|
*/
|
|
|
|
struct io_plan *daemon_conn_read_next(struct io_conn *conn,
|
|
|
|
struct daemon_conn *dc);
|
|
|
|
|
2017-03-19 21:32:44 +01:00
|
|
|
/**
|
|
|
|
* daemon_conn_sync_flush - Flush connection by sending all messages now..
|
|
|
|
*/
|
|
|
|
bool daemon_conn_sync_flush(struct daemon_conn *dc);
|
2019-05-02 02:55:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* daemon_conn_queue_length - Get number of message in outgoing queue.
|
|
|
|
*/
|
|
|
|
size_t daemon_conn_queue_length(const struct daemon_conn *dc);
|
|
|
|
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_COMMON_DAEMON_CONN_H */
|