Skip to content

Commit 8e85764

Browse files
committed
lib: remove unused functions, make single-use static
Closes curl#11174
1 parent 0768604 commit 8e85764

26 files changed

+175
-351
lines changed

lib/bufq.c

+19-11
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ void Curl_bufcp_init(struct bufc_pool *pool,
181181
pool->spare_max = spare_max;
182182
}
183183

184-
CURLcode Curl_bufcp_take(struct bufc_pool *pool,
185-
struct buf_chunk **pchunk)
184+
static CURLcode bufcp_take(struct bufc_pool *pool,
185+
struct buf_chunk **pchunk)
186186
{
187187
struct buf_chunk *chunk = NULL;
188188

@@ -205,8 +205,8 @@ CURLcode Curl_bufcp_take(struct bufc_pool *pool,
205205
return CURLE_OK;
206206
}
207207

208-
void Curl_bufcp_put(struct bufc_pool *pool,
209-
struct buf_chunk *chunk)
208+
static void bufcp_put(struct bufc_pool *pool,
209+
struct buf_chunk *chunk)
210210
{
211211
if(pool->spare_count >= pool->spare_max) {
212212
free(chunk);
@@ -335,7 +335,7 @@ static struct buf_chunk *get_spare(struct bufq *q)
335335
return NULL;
336336

337337
if(q->pool) {
338-
if(Curl_bufcp_take(q->pool, &chunk))
338+
if(bufcp_take(q->pool, &chunk))
339339
return NULL;
340340
++q->chunk_count;
341341
return chunk;
@@ -360,7 +360,7 @@ static void prune_head(struct bufq *q)
360360
if(q->tail == chunk)
361361
q->tail = q->head;
362362
if(q->pool) {
363-
Curl_bufcp_put(q->pool, chunk);
363+
bufcp_put(q->pool, chunk);
364364
--q->chunk_count;
365365
}
366366
else if((q->chunk_count > q->max_chunks) ||
@@ -605,9 +605,18 @@ ssize_t Curl_bufq_sipn(struct bufq *q, size_t max_len,
605605
return nread;
606606
}
607607

608-
ssize_t Curl_bufq_slurpn(struct bufq *q, size_t max_len,
609-
Curl_bufq_reader *reader, void *reader_ctx,
610-
CURLcode *err)
608+
/**
609+
* Read up to `max_len` bytes and append it to the end of the buffer queue.
610+
* if `max_len` is 0, no limit is imposed and the call behaves exactly
611+
* the same as `Curl_bufq_slurp()`.
612+
* Returns the total amount of buf read (may be 0) or -1 on other
613+
* reader errors.
614+
* Note that even in case of a -1 chunks may have been read and
615+
* the buffer queue will have different length than before.
616+
*/
617+
static ssize_t bufq_slurpn(struct bufq *q, size_t max_len,
618+
Curl_bufq_reader *reader, void *reader_ctx,
619+
CURLcode *err)
611620
{
612621
ssize_t nread = 0, n;
613622

@@ -646,6 +655,5 @@ ssize_t Curl_bufq_slurpn(struct bufq *q, size_t max_len,
646655
ssize_t Curl_bufq_slurp(struct bufq *q, Curl_bufq_reader *reader,
647656
void *reader_ctx, CURLcode *err)
648657
{
649-
return Curl_bufq_slurpn(q, 0, reader, reader_ctx, err);
658+
return bufq_slurpn(q, 0, reader, reader_ctx, err);
650659
}
651-

lib/bufq.h

-18
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ struct bufc_pool {
6060
void Curl_bufcp_init(struct bufc_pool *pool,
6161
size_t chunk_size, size_t spare_max);
6262

63-
CURLcode Curl_bufcp_take(struct bufc_pool *pool,
64-
struct buf_chunk **pchunk);
65-
void Curl_bufcp_put(struct bufc_pool *pool,
66-
struct buf_chunk *chunk);
67-
6863
void Curl_bufcp_free(struct bufc_pool *pool);
6964

7065
/**
@@ -251,19 +246,6 @@ typedef ssize_t Curl_bufq_reader(void *reader_ctx,
251246
ssize_t Curl_bufq_slurp(struct bufq *q, Curl_bufq_reader *reader,
252247
void *reader_ctx, CURLcode *err);
253248

254-
/**
255-
* Read up to `max_len` bytes and append it to the end of the buffer queue.
256-
* if `max_len` is 0, no limit is imposed and the call behaves exactly
257-
* the same as `Curl_bufq_slurp()`.
258-
* Returns the total amount of buf read (may be 0) or -1 on other
259-
* reader errors.
260-
* Note that even in case of a -1 chunks may have been read and
261-
* the buffer queue will have different length than before.
262-
*/
263-
ssize_t Curl_bufq_slurpn(struct bufq *q, size_t max_len,
264-
Curl_bufq_reader *reader, void *reader_ctx,
265-
CURLcode *err);
266-
267249
/**
268250
* Read *once* up to `max_len` bytes and append it to the buffer.
269251
* if `max_len` is 0, no limit is imposed besides the chunk space.

lib/cf-haproxy.c

-16
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,6 @@ static CURLcode cf_haproxy_create(struct Curl_cfilter **pcf,
228228
return result;
229229
}
230230

231-
CURLcode Curl_conn_haproxy_add(struct Curl_easy *data,
232-
struct connectdata *conn,
233-
int sockindex)
234-
{
235-
struct Curl_cfilter *cf;
236-
CURLcode result;
237-
238-
result = cf_haproxy_create(&cf, data);
239-
if(result)
240-
goto out;
241-
Curl_conn_cf_add(data, conn, sockindex, cf);
242-
243-
out:
244-
return result;
245-
}
246-
247231
CURLcode Curl_cf_haproxy_insert_after(struct Curl_cfilter *cf_at,
248232
struct Curl_easy *data)
249233
{

lib/cf-haproxy.h

-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929

3030
#if !defined(CURL_DISABLE_PROXY)
3131

32-
CURLcode Curl_conn_haproxy_add(struct Curl_easy *data,
33-
struct connectdata *conn,
34-
int sockindex);
35-
3632
CURLcode Curl_cf_haproxy_insert_after(struct Curl_cfilter *cf_at,
3733
struct Curl_easy *data);
3834

lib/cf-https-connect.c

+7-25
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,11 @@ static CURLcode cf_hc_create(struct Curl_cfilter **pcf,
496496
return result;
497497
}
498498

499-
CURLcode Curl_cf_http_connect_add(struct Curl_easy *data,
500-
struct connectdata *conn,
501-
int sockindex,
502-
const struct Curl_dns_entry *remotehost,
503-
bool try_h3, bool try_h21)
499+
static CURLcode cf_http_connect_add(struct Curl_easy *data,
500+
struct connectdata *conn,
501+
int sockindex,
502+
const struct Curl_dns_entry *remotehost,
503+
bool try_h3, bool try_h21)
504504
{
505505
struct Curl_cfilter *cf;
506506
CURLcode result = CURLE_OK;
@@ -514,24 +514,6 @@ CURLcode Curl_cf_http_connect_add(struct Curl_easy *data,
514514
return result;
515515
}
516516

517-
CURLcode
518-
Curl_cf_http_connect_insert_after(struct Curl_cfilter *cf_at,
519-
struct Curl_easy *data,
520-
const struct Curl_dns_entry *remotehost,
521-
bool try_h3, bool try_h21)
522-
{
523-
struct Curl_cfilter *cf;
524-
CURLcode result;
525-
526-
DEBUGASSERT(data);
527-
result = cf_hc_create(&cf, data, remotehost, try_h3, try_h21);
528-
if(result)
529-
goto out;
530-
Curl_conn_cf_insert_after(cf_at, cf);
531-
out:
532-
return result;
533-
}
534-
535517
CURLcode Curl_cf_https_setup(struct Curl_easy *data,
536518
struct connectdata *conn,
537519
int sockindex,
@@ -560,8 +542,8 @@ CURLcode Curl_cf_https_setup(struct Curl_easy *data,
560542
try_h21 = TRUE;
561543
}
562544

563-
result = Curl_cf_http_connect_add(data, conn, sockindex, remotehost,
564-
try_h3, try_h21);
545+
result = cf_http_connect_add(data, conn, sockindex, remotehost,
546+
try_h3, try_h21);
565547
out:
566548
return result;
567549
}

lib/cf-socket.c

+21-11
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,13 @@ tcpkeepalive(struct Curl_easy *data,
212212
}
213213
}
214214

215-
void Curl_sock_assign_addr(struct Curl_sockaddr_ex *dest,
216-
const struct Curl_addrinfo *ai,
217-
int transport)
215+
/**
216+
* Assign the address `ai` to the Curl_sockaddr_ex `dest` and
217+
* set the transport used.
218+
*/
219+
static void sock_assign_addr(struct Curl_sockaddr_ex *dest,
220+
const struct Curl_addrinfo *ai,
221+
int transport)
218222
{
219223
/*
220224
* The Curl_sockaddr_ex structure is basically libcurl's external API
@@ -306,7 +310,7 @@ CURLcode Curl_socket_open(struct Curl_easy *data,
306310
/* if the caller doesn't want info back, use a local temp copy */
307311
addr = &dummy;
308312

309-
Curl_sock_assign_addr(addr, ai, transport);
313+
sock_assign_addr(addr, ai, transport);
310314
return socket_open(data, addr, sockfd);
311315
}
312316

@@ -717,8 +721,11 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
717721
return rc;
718722
}
719723

720-
CURLcode Curl_socket_connect_result(struct Curl_easy *data,
721-
const char *ipaddress, int error)
724+
/**
725+
* Determine the curl code for a socket connect() == -1 with errno.
726+
*/
727+
static CURLcode socket_connect_result(struct Curl_easy *data,
728+
const char *ipaddress, int error)
722729
{
723730
char buffer[STRERROR_LEN];
724731

@@ -781,7 +788,7 @@ static void cf_socket_ctx_init(struct cf_socket_ctx *ctx,
781788
memset(ctx, 0, sizeof(*ctx));
782789
ctx->sock = CURL_SOCKET_BAD;
783790
ctx->transport = transport;
784-
Curl_sock_assign_addr(&ctx->addr, ai, transport);
791+
sock_assign_addr(&ctx->addr, ai, transport);
785792
Curl_bufq_init(&ctx->recvbuf, NW_RECV_CHUNK_SIZE, NW_RECV_CHUNKS);
786793
}
787794

@@ -1128,7 +1135,7 @@ static CURLcode cf_tcp_connect(struct Curl_cfilter *cf,
11281135
/* Connect TCP socket */
11291136
rc = do_connect(cf, data, cf->conn->bits.tcp_fastopen);
11301137
if(-1 == rc) {
1131-
result = Curl_socket_connect_result(data, ctx->r_ip, SOCKERRNO);
1138+
result = socket_connect_result(data, ctx->r_ip, SOCKERRNO);
11321139
goto out;
11331140
}
11341141
}
@@ -1562,7 +1569,7 @@ static CURLcode cf_udp_setup_quic(struct Curl_cfilter *cf,
15621569

15631570
rc = connect(ctx->sock, &ctx->addr.sa_addr, ctx->addr.addrlen);
15641571
if(-1 == rc) {
1565-
return Curl_socket_connect_result(data, ctx->r_ip, SOCKERRNO);
1572+
return socket_connect_result(data, ctx->r_ip, SOCKERRNO);
15661573
}
15671574
set_local_ip(cf, data);
15681575
DEBUGF(LOG_CF(data, cf, "%s socket %" CURL_FORMAT_SOCKET_T
@@ -1866,7 +1873,10 @@ CURLcode Curl_conn_tcp_accepted_set(struct Curl_easy *data,
18661873
return CURLE_OK;
18671874
}
18681875

1869-
bool Curl_cf_is_socket(struct Curl_cfilter *cf)
1876+
/**
1877+
* Return TRUE iff `cf` is a socket filter.
1878+
*/
1879+
static bool cf_is_socket(struct Curl_cfilter *cf)
18701880
{
18711881
return cf && (cf->cft == &Curl_cft_tcp ||
18721882
cf->cft == &Curl_cft_udp ||
@@ -1881,7 +1891,7 @@ CURLcode Curl_cf_socket_peek(struct Curl_cfilter *cf,
18811891
const char **pr_ip_str, int *pr_port,
18821892
const char **pl_ip_str, int *pl_port)
18831893
{
1884-
if(Curl_cf_is_socket(cf) && cf->ctx) {
1894+
if(cf_is_socket(cf) && cf->ctx) {
18851895
struct cf_socket_ctx *ctx = cf->ctx;
18861896

18871897
if(psock)

lib/cf-socket.h

-18
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ CURLcode Curl_socket_open(struct Curl_easy *data,
8787
int Curl_socket_close(struct Curl_easy *data, struct connectdata *conn,
8888
curl_socket_t sock);
8989

90-
/**
91-
* Determine the curl code for a socket connect() == -1 with errno.
92-
*/
93-
CURLcode Curl_socket_connect_result(struct Curl_easy *data,
94-
const char *ipaddress, int error);
95-
9690
#ifdef USE_WINSOCK
9791
/* When you run a program that uses the Windows Sockets API, you may
9892
experience slow performance when you copy data to a TCP server.
@@ -108,13 +102,6 @@ void Curl_sndbufset(curl_socket_t sockfd);
108102
#define Curl_sndbufset(y) Curl_nop_stmt
109103
#endif
110104

111-
/**
112-
* Assign the address `ai` to the Curl_sockaddr_ex `dest` and
113-
* set the transport used.
114-
*/
115-
void Curl_sock_assign_addr(struct Curl_sockaddr_ex *dest,
116-
const struct Curl_addrinfo *ai,
117-
int transport);
118105

119106
/**
120107
* Creates a cfilter that opens a TCP socket to the given address
@@ -171,11 +158,6 @@ CURLcode Curl_conn_tcp_accepted_set(struct Curl_easy *data,
171158
int sockindex,
172159
curl_socket_t *s);
173160

174-
/**
175-
* Return TRUE iff `cf` is a socket filter.
176-
*/
177-
bool Curl_cf_is_socket(struct Curl_cfilter *cf);
178-
179161
/**
180162
* Peek at the socket and remote ip/port the socket filter is using.
181163
* The filter owns all returned values.

0 commit comments

Comments
 (0)