@ -2,26 +2,6 @@
# include <ccan/take/take.h>
# include <ccan/take/take.h>
# include <wire/wire_io.h>
# include <wire/wire_io.h>
static void daemon_conn_enqueue ( struct daemon_conn * dc , u8 * msg )
{
size_t n = tal_count ( dc - > msg_out ) ;
tal_resize ( & dc - > msg_out , n + 1 ) ;
dc - > msg_out [ n ] = tal_dup_arr ( dc - > ctx , u8 , msg , tal_count ( msg ) , 0 ) ;
}
static const u8 * daemon_conn_dequeue ( struct daemon_conn * dc )
{
const u8 * msg ;
size_t n = tal_count ( dc - > msg_out ) ;
if ( n = = 0 )
return NULL ;
msg = dc - > msg_out [ 0 ] ;
memmove ( dc - > msg_out , dc - > msg_out + 1 , sizeof ( dc - > msg_in [ 0 ] ) * ( n - 1 ) ) ;
tal_resize ( & dc - > msg_out , n - 1 ) ;
return msg ;
}
struct io_plan * daemon_conn_read_next ( struct io_conn * conn ,
struct io_plan * daemon_conn_read_next ( struct io_conn * conn ,
struct daemon_conn * dc )
struct daemon_conn * dc )
{
{
@ -33,7 +13,7 @@ struct io_plan *daemon_conn_read_next(struct io_conn *conn,
struct io_plan * daemon_conn_write_next ( struct io_conn * conn ,
struct io_plan * daemon_conn_write_next ( struct io_conn * conn ,
struct daemon_conn * dc )
struct daemon_conn * dc )
{
{
const u8 * msg = daemon_conn _dequeue( dc ) ;
const u8 * msg = msg _dequeue( & dc - > out ) ;
if ( msg ) {
if ( msg ) {
return io_write_wire ( conn , take ( msg ) , daemon_conn_write_next ,
return io_write_wire ( conn , take ( msg ) , daemon_conn_write_next ,
dc ) ;
dc ) ;
@ -60,7 +40,7 @@ void daemon_conn_init(tal_t *ctx, struct daemon_conn *dc, int fd,
dc - > ctx = ctx ;
dc - > ctx = ctx ;
dc - > msg_in = NULL ;
dc - > msg_in = NULL ;
dc - > msg_out = tal_arr ( ctx , u8 * , 0 ) ;
msg_queue_init ( & dc - > out , dc - > ctx ) ;
dc - > conn_fd = fd ;
dc - > conn_fd = fd ;
dc - > msg_queue_cleared_cb = NULL ;
dc - > msg_queue_cleared_cb = NULL ;
io_new_conn ( ctx , fd , daemon_conn_start , dc ) ;
io_new_conn ( ctx , fd , daemon_conn_start , dc ) ;
@ -68,6 +48,6 @@ void daemon_conn_init(tal_t *ctx, struct daemon_conn *dc, int fd,
void daemon_conn_send ( struct daemon_conn * dc , u8 * msg )
void daemon_conn_send ( struct daemon_conn * dc , u8 * msg )
{
{
daemon_conn _enqueue( dc , msg ) ;
msg _enqueue( & dc - > out , msg ) ;
io_wake ( dc ) ;
io_wake ( dc ) ;
}
}