Skip to content

Cf send recv signature#17546

Closed
icing wants to merge 2 commits intocurl:masterfrom
icing:cf-send-recv-sig
Closed

Cf send recv signature#17546
icing wants to merge 2 commits intocurl:masterfrom
icing:cf-send-recv-sig

Conversation

@icing
Copy link
Contributor

@icing icing commented Jun 6, 2025

Unify the calling/return conventions in our send/receive handling. This PR does not change all such functions in libcurl, but the major ones. Others to be tackled after this PR.

cfilters: change callback function signatures:

-typedef ssize_t  Curl_cft_send(struct Curl_cfilter *cf,
+typedef CURLcode Curl_cft_send(struct Curl_cfilter *cf,
                                struct Curl_easy *data, /* transfer */
                                const void *buf,        /* data to write */
                                size_t len,             /* amount to write */
                                bool eos,               /* last chunk */
-                               CURLcode *err);         /* error to return */
+                               size_t *pnwritten);     /* how much sent */

-typedef ssize_t  Curl_cft_recv(struct Curl_cfilter *cf,
+typedef CURLcode Curl_cft_recv(struct Curl_cfilter *cf,
                                struct Curl_easy *data, /* transfer */
                                char *buf,              /* store data here */
                                size_t len,             /* amount to read */
-                               CURLcode *err);         /* error to return */
+                               size_t *pnread);        /* how much received */

Change Curl_send and Curl_recv prototypes:

-typedef ssize_t (Curl_send)(struct Curl_easy *data,   /* transfer */
+typedef CURLcode (Curl_send)(struct Curl_easy *data,   /* transfer */
                              int sockindex,            /* socketindex */
                              const void *buf,          /* data to write */
                              size_t len,               /* max amount to write */
                              bool eos,                 /* last chunk */
-                             CURLcode *err);           /* error to return */
+                             size_t *pnwritten);       /* how much sent */

-typedef ssize_t (Curl_recv)(struct Curl_easy *data,   /* transfer */
+typedef CURLcode (Curl_recv)(struct Curl_easy *data,   /* transfer */
                              int sockindex,            /* socketindex */
                              char *buf,                /* store data here */
                              size_t len,               /* max amount to read */
-                             CURLcode *err);           /* error to return */
+                             size_t *pnread);          /* how much received */

The new form is peferrable:

  1. The success is based on the return value alone. In case of error, the value of the size_t * parameter is meaningless. This simplifies handling of errors after the size_t * has been assigned.
  2. The former ssize_t return value always needed conversion to size_t when not negative. This is now unnecessary.
  3. Some checks had been on a return value of -1 which left other negative returns in undefined state.

Curl_conn_recv(): adjust pnread type:
Parameter pnread was a ssizet_t *, but size_t * is better since the function returns any error in its CURLcode return value.

@curl curl deleted a comment from testclutch Jun 6, 2025
@icing icing force-pushed the cf-send-recv-sig branch from 19d259c to 953f1ab Compare June 11, 2025 07:59
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 `ssizet_t *`, but `size_t *` is better
since the function returns any error in its `CURLcode` return value.
@icing icing force-pushed the cf-send-recv-sig branch from 953f1ab to d1a8fc5 Compare June 11, 2025 08:22
@icing icing marked this pull request as ready for review June 11, 2025 08:28
@icing icing added the tidy-up label Jun 11, 2025
@icing icing requested a review from bagder June 11, 2025 09:17
@bagder bagder closed this in 20c90ba Jun 11, 2025
denandz pushed a commit to denandz/curl that referenced this pull request Jun 21, 2025
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 curl#17546
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants