From a67aed73cd0bfa48b1f53fcbaeae1bdea630e8ec Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 28 Mar 2023 16:26:36 -0400 Subject: [PATCH] MT#56447 add ng_buffer_new Change-Id: I3650e847813964fde75d10790864eb2e6c4c265b --- daemon/control_ng.c | 20 +++++++++++++------- include/control_ng.h | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/daemon/control_ng.c b/daemon/control_ng.c index 7ae2d9016..90e79be2d 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -127,6 +127,18 @@ static void __ng_buffer_free(void *p) { obj_put_o(ngbuf->ref); } +struct ng_buffer *ng_buffer_new(struct obj *ref) { + struct ng_buffer *ngbuf = obj_alloc0("ng_buffer", sizeof(*ngbuf), __ng_buffer_free); + if (ref) + ngbuf->ref = obj_get_o(ref); // hold until we're done + + int ret = bencode_buffer_init(&ngbuf->buffer); + assert(ret == 0); + (void) ret; + + return ngbuf; +} + int control_ng_process(str *buf, const endpoint_t *sin, char *addr, void (*cb)(str *, str *, const endpoint_t *, void *), void *p1, struct obj *ref) { @@ -147,14 +159,8 @@ int control_ng_process(str *buf, const endpoint_t *sin, char *addr, return funcret; } - // init decode buffer object - ngbuf = obj_alloc0("ng_buffer", sizeof(*ngbuf), __ng_buffer_free); - if (ref) - ngbuf->ref = obj_get_o(ref); // hold until we're done + ngbuf = ng_buffer_new(ref); - int ret = bencode_buffer_init(&ngbuf->buffer); - assert(ret == 0); - (void) ret; resp = bencode_dictionary(&ngbuf->buffer); assert(resp != NULL); diff --git a/include/control_ng.h b/include/control_ng.h index f6883897a..d3deecdd9 100644 --- a/include/control_ng.h +++ b/include/control_ng.h @@ -76,6 +76,8 @@ void control_ng_cleanup(void); int control_ng_process(str *buf, const endpoint_t *sin, char *addr, void (*cb)(str *, str *, const endpoint_t *, void *), void *p1, struct obj *); +struct ng_buffer *ng_buffer_new(struct obj *ref); + INLINE void ng_buffer_release(struct ng_buffer *ngbuf) { obj_put(ngbuf); }