Browse Source
Some of the simple daemons want to use this, as do the status messages. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>ppa-0.6.1
Rusty Russell
8 years ago
3 changed files with 40 additions and 2 deletions
@ -0,0 +1,26 @@ |
|||
#include "wire/wire_sync.h" |
|||
#include <assert.h> |
|||
#include <ccan/endian/endian.h> |
|||
#include <ccan/read_write_all/read_write_all.h> |
|||
|
|||
bool wire_sync_write(int fd, const void *msg) |
|||
{ |
|||
be16 be_len = cpu_to_be16(tal_count(msg)); |
|||
|
|||
assert(be16_to_cpu(be_len) == tal_count(msg)); |
|||
return write_all(fd, &be_len, sizeof(be_len)) |
|||
&& write_all(fd, msg, tal_count(msg)); |
|||
} |
|||
|
|||
u8 *wire_sync_read(const tal_t *ctx, int fd) |
|||
{ |
|||
be16 be_len; |
|||
u8 *msg; |
|||
|
|||
if (!read_all(fd, &be_len, sizeof(be_len))) |
|||
return NULL; |
|||
msg = tal_arr(ctx, u8, be16_to_cpu(be_len)); |
|||
if (!read_all(fd, msg, be16_to_cpu(be_len))) |
|||
return tal_free(msg); |
|||
return msg; |
|||
} |
@ -0,0 +1,10 @@ |
|||
#ifndef LIGHTNING_WIRE_WIRE_SYNC_H |
|||
#define LIGHTNING_WIRE_WIRE_SYNC_H |
|||
#include "config.h" |
|||
#include <ccan/short_types/short_types.h> |
|||
#include <ccan/tal/tal.h> |
|||
|
|||
bool wire_sync_write(int fd, const void *msg); |
|||
u8 *wire_sync_read(const tal_t *ctx, int fd); |
|||
|
|||
#endif /* LIGHTNING_WIRE_WIRE_SYNC_H */ |
Loading…
Reference in new issue