lightningd/connection: add fd support.

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 22d2392454
commit 6dd07801d4
2 changed files with 15 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include "connection.h"
#include <ccan/io/fdpass/fdpass.h>
#include <ccan/take/take.h>
#include <wire/wire_io.h>
@ -15,6 +16,10 @@ struct io_plan *daemon_conn_write_next(struct io_conn *conn,
{
const u8 *msg = msg_dequeue(&dc->out);
if (msg) {
int fd = msg_is_fd(msg);
if (fd >= 0)
return io_send_fd(conn, fd, true,
daemon_conn_write_next, dc);
return io_write_wire(conn, take(msg), daemon_conn_write_next,
dc);
} else if (dc->msg_queue_cleared_cb) {
@ -51,3 +56,8 @@ void daemon_conn_send(struct daemon_conn *dc, const u8 *msg)
{
msg_enqueue(&dc->out, msg);
}
void daemon_conn_send_fd(struct daemon_conn *dc, int fd)
{
msg_enqueue_fd(&dc->out, fd);
}

View File

@ -46,6 +46,11 @@ void daemon_conn_init(tal_t *ctx, struct daemon_conn *dc, int fd,
*/
void daemon_conn_send(struct daemon_conn *dc, const u8 *msg);
/**
* 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_write_next - Continue writing from the msg-queue
*