Skip to content

Commit ecff6f1

Browse files
committed
lightningd: allow subd_req() to take replycb_data arg.
Useful if it's only to be used for the duration of the callback. Signed-off-by: Rusty Russell <[email protected]>
1 parent 329962e commit ecff6f1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lightningd/subd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,15 @@ static struct subd_req *add_req(const tal_t *ctx,
142142
struct subd *sd, int type, size_t num_fds_in,
143143
void (*replycb)(struct subd *, const u8 *, const int *,
144144
void *),
145-
void *replycb_data)
145+
void *replycb_data TAKES)
146146
{
147147
struct subd_req *sr = tal(sd, struct subd_req);
148148

149149
sr->type = type;
150150
sr->replycb = replycb;
151151
sr->replycb_data = replycb_data;
152+
if (taken(replycb_data))
153+
tal_steal(sr, replycb_data);
152154
sr->num_reply_fds = num_fds_in;
153155

154156
/* We don't allocate sr off ctx, because we still have to handle the
@@ -852,7 +854,7 @@ struct subd_req *subd_req_(const tal_t *ctx,
852854
const u8 *msg_out,
853855
int fd_out, size_t num_fds_in,
854856
void (*replycb)(struct subd *, const u8 *, const int *, void *),
855-
void *replycb_data)
857+
void *replycb_data TAKES)
856858
{
857859
/* Grab type now in case msg_out is taken() */
858860
int type = fromwire_peektype(msg_out);

lightningd/subd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void subd_send_fd(struct subd *sd, int fd);
178178
* @fd_out: if >=0 fd to pass at the end of the message (closed after)
179179
* @num_fds_in: how many fds to read in to hand to @replycb if it's a reply.
180180
* @replycb: callback (inside db transaction) when reply comes in (can free subd)
181-
* @replycb_data: final arg to hand to @replycb
181+
* @replycb_data: final arg to hand to @replycb (can be TAKE())
182182
*
183183
* @replycb cannot free @sd, so it returns false to remove it.
184184
* Note that @replycb is called for replies of type @msg_out + SUBD_REPLY_OFFSET
@@ -196,7 +196,7 @@ struct subd_req *subd_req_(const tal_t *ctx,
196196
const u8 *msg_out,
197197
int fd_out, size_t num_fds_in,
198198
void (*replycb)(struct subd *, const u8 *, const int *, void *),
199-
void *replycb_data);
199+
void *replycb_data TAKES);
200200

201201
/**
202202
* subd_release_channel - shut down a subdaemon which no longer owns the channel.

0 commit comments

Comments
 (0)