Browse Source

MT#56447 add ng_buffer_new

Change-Id: I3650e847813964fde75d10790864eb2e6c4c265b
pull/1642/head
Richard Fuchs 3 years ago
parent
commit
a67aed73cd
2 changed files with 15 additions and 7 deletions
  1. +13
    -7
      daemon/control_ng.c
  2. +2
    -0
      include/control_ng.h

+ 13
- 7
daemon/control_ng.c View File

@ -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);


+ 2
- 0
include/control_ng.h View File

@ -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);
}


Loading…
Cancel
Save