mg_rpc_free -> mg_rpc_del

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

No files matched your search

+10 -6
View File
@@ -3573,12 +3573,16 @@ void mg_rpc_add(void **head, struct mg_str method,
rpc->next = (struct mg_rpc *) *head, *head = rpc; rpc->next = (struct mg_rpc *) *head, *head = rpc;
} }
void mg_rpc_free(void **head) { void mg_rpc_del(void **head, void (*fn)(struct mg_rpc_req *)) {
while (head != NULL && *head != NULL) { struct mg_rpc *r, **h = (struct mg_rpc **) head;
struct mg_rpc *rpc = *(struct mg_rpc **) head; while ((r = *h) != NULL) {
*head = rpc->next; if (r->fn == fn || fn == NULL) {
free((void *) rpc->method.ptr); *h = r->next;
free(rpc); free((void *) r->method.ptr);
free(r);
} else {
h = &(*h)->next;
}
} }
} }
+1 -1
View File
@@ -1374,7 +1374,7 @@ struct mg_rpc_req {
void mg_rpc_add(void **head, struct mg_str method_pattern, void mg_rpc_add(void **head, struct mg_str method_pattern,
void (*handler)(struct mg_rpc_req *), void *handler_data); 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 *); void mg_rpc_process(struct mg_rpc_req *);
// Helper functions to print result or error frame // Helper functions to print result or error frame
+10 -6
View File
@@ -14,12 +14,16 @@ void mg_rpc_add(void **head, struct mg_str method,
rpc->next = (struct mg_rpc *) *head, *head = rpc; rpc->next = (struct mg_rpc *) *head, *head = rpc;
} }
void mg_rpc_free(void **head) { void mg_rpc_del(void **head, void (*fn)(struct mg_rpc_req *)) {
while (head != NULL && *head != NULL) { struct mg_rpc *r, **h = (struct mg_rpc **) head;
struct mg_rpc *rpc = *(struct mg_rpc **) head; while ((r = *h) != NULL) {
*head = rpc->next; if (r->fn == fn || fn == NULL) {
free((void *) rpc->method.ptr); *h = r->next;
free(rpc); free((void *) r->method.ptr);
free(r);
} else {
h = &(*h)->next;
}
} }
} }
+1 -1
View File
@@ -14,7 +14,7 @@ struct mg_rpc_req {
void mg_rpc_add(void **head, struct mg_str method_pattern, void mg_rpc_add(void **head, struct mg_str method_pattern,
void (*handler)(struct mg_rpc_req *), void *handler_data); 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 *); void mg_rpc_process(struct mg_rpc_req *);
// Helper functions to print result or error frame // Helper functions to print result or error frame
+1 -1
View File
@@ -2476,7 +2476,7 @@ static void test_rpc(void) {
free(s), s = NULL; free(s), s = NULL;
} }
mg_rpc_free(&head); mg_rpc_del(&head, NULL);
ASSERT(head == NULL); ASSERT(head == NULL);
} }