lib: unify recv/send function signatures

cfilter/conn: change send/recv function signatures. Unify the
calling/return conventions in our send/receive handling.

Curl_conn_recv(), adjust pnread type

Parameter `pnread` was a `ssize_t *`, but `size_t *` is better since the
function returns any error in its `CURLcode` return value.

Closes #17546
This commit is contained in:
Stefan Eissing 2025-06-11 10:18:15 +02:00 committed by Daniel Stenberg
parent 3934431421
commit 20c90ba298
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
37 changed files with 1114 additions and 1219 deletions

View file

@ -81,7 +81,7 @@ enum connect_t {
struct socks_state {
enum connect_t state;
ssize_t outstanding; /* send this many bytes more */
size_t outstanding; /* send this many bytes more */
unsigned char buffer[CURL_SOCKS_BUF_SIZE];
unsigned char *outp; /* send from this pointer */
@ -101,54 +101,41 @@ struct socks_state {
int Curl_blockread_all(struct Curl_cfilter *cf,
struct Curl_easy *data, /* transfer */
char *buf, /* store read data here */
ssize_t buffersize, /* max amount to read */
ssize_t *n) /* amount bytes read */
size_t blen, /* space in buf */
size_t *pnread) /* amount bytes read */
{
ssize_t nread = 0;
ssize_t allread = 0;
int result;
CURLcode err = CURLE_OK;
size_t nread = 0;
CURLcode err;
*n = 0;
*pnread = 0;
for(;;) {
timediff_t timeout_ms = Curl_timeleft(data, NULL, TRUE);
if(timeout_ms < 0) {
/* we already got the timeout */
result = CURLE_OPERATION_TIMEDOUT;
break;
return CURLE_OPERATION_TIMEDOUT;
}
if(!timeout_ms)
timeout_ms = TIMEDIFF_T_MAX;
if(SOCKET_READABLE(cf->conn->sock[cf->sockindex], timeout_ms) <= 0) {
result = ~CURLE_OK;
break;
}
nread = Curl_conn_cf_recv(cf->next, data, buf, buffersize, &err);
if(nread <= 0) {
result = (int)err;
if(CURLE_AGAIN == err)
continue;
if(err) {
break;
}
return ~CURLE_OK;
}
err = Curl_conn_cf_recv(cf->next, data, buf, blen, &nread);
if(CURLE_AGAIN == err)
continue;
else if(err)
return (int)err;
if(buffersize == nread) {
allread += nread;
*n = allread;
result = CURLE_OK;
break;
}
if(!nread) {
result = ~CURLE_OK;
break;
if(blen == nread) {
*pnread += nread;
return CURLE_OK;
}
if(!nread) /* EOF */
return ~CURLE_OK;
buffersize -= nread;
buf += nread;
allread += nread;
blen -= nread;
*pnread += nread;
}
return result;
}
#endif
@ -213,24 +200,25 @@ static CURLproxycode socks_state_send(struct Curl_cfilter *cf,
CURLproxycode failcode,
const char *description)
{
ssize_t nwritten;
size_t nwritten;
CURLcode result;
nwritten = Curl_conn_cf_send(cf->next, data, (char *)sx->outp,
sx->outstanding, FALSE, &result);
if(nwritten <= 0) {
if(CURLE_AGAIN == result) {
result = Curl_conn_cf_send(cf->next, data, (char *)sx->outp,
sx->outstanding, FALSE, &nwritten);
if(result) {
if(CURLE_AGAIN == result)
return CURLPX_OK;
}
else if(CURLE_OK == result) {
/* connection closed */
failf(data, "connection to proxy closed");
return CURLPX_CLOSED;
}
failf(data, "Failed to send %s: %s", description,
curl_easy_strerror(result));
return failcode;
}
else if(!nwritten) {
/* connection closed */
failf(data, "connection to proxy closed");
return CURLPX_CLOSED;
}
DEBUGASSERT(sx->outstanding >= nwritten);
/* not done, remain in state */
sx->outstanding -= nwritten;
@ -244,24 +232,24 @@ static CURLproxycode socks_state_recv(struct Curl_cfilter *cf,
CURLproxycode failcode,
const char *description)
{
ssize_t nread;
size_t nread;
CURLcode result;
nread = Curl_conn_cf_recv(cf->next, data, (char *)sx->outp,
sx->outstanding, &result);
if(nread <= 0) {
if(CURLE_AGAIN == result) {
result = Curl_conn_cf_recv(cf->next, data, (char *)sx->outp,
sx->outstanding, &nread);
if(result) {
if(CURLE_AGAIN == result)
return CURLPX_OK;
}
else if(CURLE_OK == result) {
/* connection closed */
failf(data, "connection to proxy closed");
return CURLPX_CLOSED;
}
failf(data, "SOCKS: Failed receiving %s: %s", description,
curl_easy_strerror(result));
return failcode;
}
else if(!nread) {
/* connection closed */
failf(data, "connection to proxy closed");
return CURLPX_CLOSED;
}
/* remain in reading state */
DEBUGASSERT(sx->outstanding >= nread);
sx->outstanding -= nread;