mg_rpc_free -> mg_rpc_del

This commit is contained in:
Sergey Lyubka 2022-07-30 21:13:30 +01:00
parent 43d53b0616
commit f02f88f336
5 changed files with 23 additions and 15 deletions

View File

@ -3573,12 +3573,16 @@ void mg_rpc_add(void **head, struct mg_str method,
rpc->next = (struct mg_rpc *) *head, *head = rpc;
}
void mg_rpc_free(void **head) {
while (head != NULL && *head != NULL) {
struct mg_rpc *rpc = *(struct mg_rpc **) head;
*head = rpc->next;
free((void *) rpc->method.ptr);
free(rpc);
void mg_rpc_del(void **head, void (*fn)(struct mg_rpc_req *)) {
struct mg_rpc *r, **h = (struct mg_rpc **) head;
while ((r = *h) != NULL) {
if (r->fn == fn || fn == NULL) {
*h = r->next;
free((void *) r->method.ptr);
free(r);
} else {
h = &(*h)->next;
}
}
}

View File

@ -1374,7 +1374,7 @@ struct mg_rpc_req {
void mg_rpc_add(void **head, struct mg_str method_pattern,
void (*handler)(struct mg_rpc_req *), void *handler_data);
void mg_rpc_free(void **head);
void mg_rpc_del(void **head, void (*handler)(struct mg_rpc_req *));
void mg_rpc_process(struct mg_rpc_req *);
// Helper functions to print result or error frame

View File

@ -14,12 +14,16 @@ void mg_rpc_add(void **head, struct mg_str method,
rpc->next = (struct mg_rpc *) *head, *head = rpc;
}
void mg_rpc_free(void **head) {
while (head != NULL && *head != NULL) {
struct mg_rpc *rpc = *(struct mg_rpc **) head;
*head = rpc->next;
free((void *) rpc->method.ptr);
free(rpc);
void mg_rpc_del(void **head, void (*fn)(struct mg_rpc_req *)) {
struct mg_rpc *r, **h = (struct mg_rpc **) head;
while ((r = *h) != NULL) {
if (r->fn == fn || fn == NULL) {
*h = r->next;
free((void *) r->method.ptr);
free(r);
} else {
h = &(*h)->next;
}
}
}

View File

@ -14,7 +14,7 @@ struct mg_rpc_req {
void mg_rpc_add(void **head, struct mg_str method_pattern,
void (*handler)(struct mg_rpc_req *), void *handler_data);
void mg_rpc_free(void **head);
void mg_rpc_del(void **head, void (*handler)(struct mg_rpc_req *));
void mg_rpc_process(struct mg_rpc_req *);
// Helper functions to print result or error frame

View File

@ -2476,7 +2476,7 @@ static void test_rpc(void) {
free(s), s = NULL;
}
mg_rpc_free(&head);
mg_rpc_del(&head, NULL);
ASSERT(head == NULL);
}