mirror of
https://github.com/curl/curl.git
synced 2025-09-13 15:42:39 +03:00
llist: add Curl_llist_append()
- use for better readability in all places where the "insert_next" actually performs an append to the list - add some tests in unit1300 Closes #13336
This commit is contained in:
parent
8cee4c9238
commit
c296abd42d
|
@ -191,7 +191,7 @@ static CURLcode altsvc_add(struct altsvcinfo *asi, char *line)
|
|||
as->expires = expires;
|
||||
as->prio = prio;
|
||||
as->persist = persist ? 1 : 0;
|
||||
Curl_llist_insert_next(&asi->list, asi->list.tail, as, &as->node);
|
||||
Curl_llist_append(&asi->list, as, &as->node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -643,7 +643,7 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
|
|||
account. [See RFC 7838 section 3.1] */
|
||||
as->expires = maxage + time(NULL);
|
||||
as->persist = persist;
|
||||
Curl_llist_insert_next(&asi->list, asi->list.tail, as, &as->node);
|
||||
Curl_llist_append(&asi->list, as, &as->node);
|
||||
infof(data, "Added alt-svc: %s:%d over %s", dsthost, dstport,
|
||||
Curl_alpnid2str(dstalpnid));
|
||||
}
|
||||
|
|
|
@ -68,8 +68,7 @@ static void bundle_destroy(struct connectbundle *bundle)
|
|||
static void bundle_add_conn(struct connectbundle *bundle,
|
||||
struct connectdata *conn)
|
||||
{
|
||||
Curl_llist_insert_next(&bundle->conn_list, bundle->conn_list.tail, conn,
|
||||
&conn->bundle_node);
|
||||
Curl_llist_append(&bundle->conn_list, conn, &conn->bundle_node);
|
||||
conn->bundle = bundle;
|
||||
bundle->num_connections++;
|
||||
}
|
||||
|
|
|
@ -349,7 +349,7 @@ static CURLcode ftp_pl_insert_finfo(struct Curl_easy *data,
|
|||
Curl_set_in_callback(data, false);
|
||||
|
||||
if(add) {
|
||||
Curl_llist_insert_next(llist, llist->tail, finfo, &infop->list);
|
||||
Curl_llist_append(llist, finfo, &infop->list);
|
||||
}
|
||||
else {
|
||||
Curl_fileinfo_cleanup(infop);
|
||||
|
|
|
@ -132,7 +132,7 @@ Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p)
|
|||
|
||||
he = mk_hash_element(key, key_len, p);
|
||||
if(he) {
|
||||
Curl_llist_insert_next(l, l->tail, he, &he->list);
|
||||
Curl_llist_append(l, he, &he->list);
|
||||
++h->size;
|
||||
return p; /* return the new entry */
|
||||
}
|
||||
|
|
|
@ -264,8 +264,7 @@ static CURLcode unfold_value(struct Curl_easy *data, const char *value,
|
|||
newhs->value[olen + vlen] = 0; /* null-terminate at newline */
|
||||
|
||||
/* insert this node into the list of headers */
|
||||
Curl_llist_insert_next(&data->state.httphdrs, data->state.httphdrs.tail,
|
||||
newhs, &newhs->node);
|
||||
Curl_llist_append(&data->state.httphdrs, newhs, &newhs->node);
|
||||
data->state.prevhead = newhs;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
@ -328,8 +327,7 @@ CURLcode Curl_headers_push(struct Curl_easy *data, const char *header,
|
|||
hs->request = data->state.requests;
|
||||
|
||||
/* insert this node into the list of headers */
|
||||
Curl_llist_insert_next(&data->state.httphdrs, data->state.httphdrs.tail,
|
||||
hs, &hs->node);
|
||||
Curl_llist_append(&data->state.httphdrs, hs, &hs->node);
|
||||
data->state.prevhead = hs;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -140,7 +140,7 @@ static CURLcode hsts_create(struct hsts *h,
|
|||
sts->host = duphost;
|
||||
sts->expires = expires;
|
||||
sts->includeSubDomains = subdomains;
|
||||
Curl_llist_insert_next(&h->list, h->list.tail, sts, &sts->node);
|
||||
Curl_llist_append(&h->list, sts, &sts->node);
|
||||
}
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
|
16
lib/llist.c
16
lib/llist.c
|
@ -88,6 +88,22 @@ Curl_llist_insert_next(struct Curl_llist *list, struct Curl_llist_element *e,
|
|||
++list->size;
|
||||
}
|
||||
|
||||
/*
|
||||
* Curl_llist_append()
|
||||
*
|
||||
* Adds a new list element to the end of the list.
|
||||
*
|
||||
* The 'ne' argument should be a pointer into the object to store.
|
||||
*
|
||||
* @unittest: 1300
|
||||
*/
|
||||
void
|
||||
Curl_llist_append(struct Curl_llist *list, const void *p,
|
||||
struct Curl_llist_element *ne)
|
||||
{
|
||||
Curl_llist_insert_next(list, list->tail, p, ne);
|
||||
}
|
||||
|
||||
/*
|
||||
* @unittest: 1300
|
||||
*/
|
||||
|
|
|
@ -45,6 +45,8 @@ struct Curl_llist {
|
|||
void Curl_llist_init(struct Curl_llist *, Curl_llist_dtor);
|
||||
void Curl_llist_insert_next(struct Curl_llist *, struct Curl_llist_element *,
|
||||
const void *, struct Curl_llist_element *node);
|
||||
void Curl_llist_append(struct Curl_llist *,
|
||||
const void *, struct Curl_llist_element *node);
|
||||
void Curl_llist_remove(struct Curl_llist *, struct Curl_llist_element *,
|
||||
void *);
|
||||
size_t Curl_llist_count(struct Curl_llist *);
|
||||
|
|
12
lib/multi.c
12
lib/multi.c
|
@ -374,8 +374,7 @@ static void sh_init(struct Curl_hash *hash, int hashsize)
|
|||
*/
|
||||
static void multi_addmsg(struct Curl_multi *multi, struct Curl_message *msg)
|
||||
{
|
||||
Curl_llist_insert_next(&multi->msglist, multi->msglist.tail, msg,
|
||||
&msg->list);
|
||||
Curl_llist_append(&multi->msglist, msg, &msg->list);
|
||||
}
|
||||
|
||||
struct Curl_multi *Curl_multi_handle(int hashsize, /* socket hash */
|
||||
|
@ -1002,8 +1001,7 @@ void Curl_attach_connection(struct Curl_easy *data,
|
|||
DEBUGASSERT(!data->conn);
|
||||
DEBUGASSERT(conn);
|
||||
data->conn = conn;
|
||||
Curl_llist_insert_next(&conn->easyq, conn->easyq.tail, data,
|
||||
&data->conn_queue);
|
||||
Curl_llist_append(&conn->easyq, data, &data->conn_queue);
|
||||
if(conn->handler && conn->handler->attach)
|
||||
conn->handler->attach(data, conn);
|
||||
Curl_conn_ev_data_attach(conn, data);
|
||||
|
@ -1996,8 +1994,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
|
|||
multistate(data, MSTATE_PENDING);
|
||||
|
||||
/* add this handle to the list of connect-pending handles */
|
||||
Curl_llist_insert_next(&multi->pending, multi->pending.tail, data,
|
||||
&data->connect_queue);
|
||||
Curl_llist_append(&multi->pending, data, &data->connect_queue);
|
||||
/* unlink from the main list */
|
||||
unlink_easy(multi, data);
|
||||
result = CURLE_OK;
|
||||
|
@ -2720,8 +2717,7 @@ statemachine_end:
|
|||
multistate(data, MSTATE_MSGSENT);
|
||||
|
||||
/* add this handle to the list of msgsent handles */
|
||||
Curl_llist_insert_next(&multi->msgsent, multi->msgsent.tail, data,
|
||||
&data->connect_queue);
|
||||
Curl_llist_append(&multi->msgsent, data, &data->connect_queue);
|
||||
/* unlink from the main list */
|
||||
unlink_easy(multi, data);
|
||||
return CURLM_OK;
|
||||
|
|
|
@ -179,7 +179,7 @@ struct Curl_multi {
|
|||
BIT(dead); /* a callback returned error, everything needs to crash and
|
||||
burn */
|
||||
BIT(xfer_buf_borrowed); /* xfer_buf is currently being borrowed */
|
||||
BIT(xfer_ulbuf_borrowed); /* xfer_buf is currently being borrowed */
|
||||
BIT(xfer_ulbuf_borrowed); /* xfer_ulbuf is currently being borrowed */
|
||||
#ifdef DEBUGBUILD
|
||||
BIT(warned); /* true after user warned of DEBUGBUILD */
|
||||
#endif
|
||||
|
|
|
@ -217,6 +217,54 @@ UNITTEST_START
|
|||
fail_unless(llist.tail == NULL,
|
||||
"llist tail is not NULL while the llist is empty");
|
||||
|
||||
/**
|
||||
* testing Curl_llist_append
|
||||
* case 1:
|
||||
* list is empty
|
||||
* @assumptions:
|
||||
* 1: the element next to head should be our newly created element
|
||||
* 2: the list tail should different from newly created element
|
||||
*/
|
||||
Curl_llist_append(&llist, &unusedData_case1, &case1_list);
|
||||
fail_unless(Curl_llist_count(&llist) == 1,
|
||||
"List size should be 1 after appending a new element");
|
||||
/* test that the list head data holds my unusedData */
|
||||
fail_unless(llist.head->ptr == &unusedData_case1,
|
||||
"head ptr should be first entry");
|
||||
/* same goes for the list tail */
|
||||
fail_unless(llist.tail == llist.head,
|
||||
"tail and head should be the same");
|
||||
|
||||
/**
|
||||
* testing Curl_llist_append
|
||||
* case 2:
|
||||
* list is not empty
|
||||
* @assumptions:
|
||||
* 1: the list head-next should be the newly created element
|
||||
* 2: the list tail should be the newly created element
|
||||
*/
|
||||
Curl_llist_append(&llist, &unusedData_case2, &case2_list);
|
||||
fail_unless(llist.head->next->ptr == &unusedData_case2,
|
||||
"the node next to head is not getting set correctly");
|
||||
fail_unless(llist.tail->ptr == &unusedData_case2,
|
||||
"the list tail is not getting set correctly");
|
||||
|
||||
/**
|
||||
* testing Curl_llist_append
|
||||
* case 3:
|
||||
* list is has 2 members
|
||||
* @assumptions:
|
||||
* 1: the list head-next should remain the same
|
||||
* 2: the list tail should be the newly created element
|
||||
*/
|
||||
Curl_llist_append(&llist, &unusedData_case3, &case3_list);
|
||||
fail_unless(llist.head->next->ptr == &unusedData_case2,
|
||||
"the node next to head did not stay the same");
|
||||
fail_unless(llist.tail->ptr == &unusedData_case3,
|
||||
"the list tail is not getting set correctly");
|
||||
|
||||
|
||||
|
||||
Curl_llist_destroy(&llist, NULL);
|
||||
Curl_llist_destroy(&llist_destination, NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user