diff --git a/nest/proto.c b/nest/proto.c index 5ddfb31e..03f502f7 100644 --- a/nest/proto.c +++ b/nest/proto.c @@ -759,8 +759,7 @@ channel_feed_end(struct channel *c) for (struct channel_feeding_request *cfr = c->refeeding, *next = cfr ? cfr->next : NULL; cfr; (cfr = next), (next = next ? next->next : NULL)) - if (cfr->flags & CFRF_DYNAMIC) - mb_free(cfr); + CALL(cfr->done, cfr); /* Drop the refeed batch */ c->refeeding = NULL; @@ -1010,12 +1009,21 @@ channel_request_feeding(struct channel *c, struct channel_feeding_request *cfr) channel_init_feeding(c); } +static void +channel_feeding_request_done_dynamic(struct channel_feeding_request *req) +{ + mb_free(req); +} + void channel_request_feeding_dynamic(struct channel *c, enum channel_feeding_request_type type) { - struct channel_feeding_request *req = mb_allocz(c->proto->pool, sizeof *req); - req->type = type; - req->flags |= CFRF_DYNAMIC; + struct channel_feeding_request *req = mb_alloc(c->proto->pool, sizeof *req); + *req = (struct channel_feeding_request) { + .type = type, + .done = channel_feeding_request_done_dynamic, + }; + channel_request_feeding(c, req); } diff --git a/nest/protocol.h b/nest/protocol.h index ca33a7fc..7d0041f5 100644 --- a/nest/protocol.h +++ b/nest/protocol.h @@ -676,19 +676,17 @@ static inline void channel_open(struct channel *c) { channel_set_state(c, CS_UP) static inline void channel_close(struct channel *c) { channel_set_state(c, CS_STOP); } struct channel_feeding_request { - struct channel_feeding_request *next; + struct channel_feeding_request *next; /* Next in request chain */ + void (*done)(struct channel_feeding_request *); /* Called when refeed finishes */ PACKED enum channel_feeding_request_type { - CFRT_DIRECT = 1, - CFRT_AUXILIARY, + CFRT_DIRECT = 1, /* Refeed by export restart */ + CFRT_AUXILIARY, /* Refeed by auxiliary request */ } type; PACKED enum { - CFRS_INACTIVE = 0, - CFRS_PENDING, - CFRS_RUNNING, + CFRS_INACTIVE = 0, /* Inactive request */ + CFRS_PENDING, /* Request enqueued, do not touch */ + CFRS_RUNNING, /* Request active, do not touch */ } state; - PACKED enum { - CFRF_DYNAMIC = 1, - } flags; }; struct channel *channel_from_export_request(struct rt_export_request *req);