mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-14 01:38:01 +08:00
mg_rpc_free -> mg_rpc_del
This commit is contained in:
parent
43d53b0616
commit
f02f88f336
16
mongoose.c
16
mongoose.c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
16
src/rpc.c
16
src/rpc.c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user