git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jiří Hruška" <jirka@fud.cz>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>,
	Jonathan Tan <jonathantanmy@google.com>,
	 Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 2/5] remote-curl: improve readability of curl callbacks
Date: Tue, 14 Nov 2023 19:34:52 -0800	[thread overview]
Message-ID: <CAGE_+C6ukSe-XTS2x8j3QDJ96yMib7kOtMbcrXes4zNbix0Oyg@mail.gmail.com> (raw)
In-Reply-To: <20231115033121.939-1-jirka@fud.cz>

The "user data" or "context" argument of libcurl streaming callbacks
is sometimes called `clientp` and sometimes `buffer_`. The latter is
especially confusing, because there is an actual buffer pointer
argument passed to the same functions.

- Make the argument consistently named `userdata` everywhere, just
  like the official cURL documentation calls it.

- Also add comments to all the callbacks, to make it easier to grasp
  what is the "in" and what is the "out" direction in this code.

Signed-off-by: Jiri Hruska <jirka@fud.cz>
---
 remote-curl.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/remote-curl.c b/remote-curl.c
index 199c4615a5..428dd70aa1 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -675,11 +675,18 @@ static int rpc_read_from_out(struct rpc_state
*rpc, int options,
 	return 1;
 }

+/*
+ * CURLOPT_READFUNCTION callback, called by libcurl when it wants more data
+ * to send out. Used only if the request did not fit into just one buffer and
+ * data must be streamed as it comes.
+ * Has the same semantics as fread(), but reads packets from the pipe from
+ * the child process instead. A return value of 0 (EOF) finishes the upload.
+ */
 static size_t rpc_out(void *ptr, size_t eltsize,
-		size_t nmemb, void *buffer_)
+		size_t nmemb, void *userdata)
 {
 	size_t max = eltsize * nmemb;
-	struct rpc_state *rpc = buffer_;
+	struct rpc_state *rpc = userdata;
 	size_t avail = rpc->len - rpc->pos;
 	enum packet_read_status status;

@@ -725,9 +732,16 @@ static size_t rpc_out(void *ptr, size_t eltsize,
 	return avail;
 }

-static int rpc_seek(void *clientp, curl_off_t offset, int origin)
+/*
+ * CURLOPT_SEEKFUNCTION callback, called by libcurl when it wants to seek in
+ * the data being sent out. Used only if the request did not fit into just
+ * one buffer and data must be streamed as it comes.
+ * Has the same semantics as fseek(), but seeks in the buffered packet read
+ * from the pipe from the child process instead.
+ */
+static int rpc_seek(void *userdata, curl_off_t offset, int origin)
 {
-	struct rpc_state *rpc = clientp;
+	struct rpc_state *rpc = userdata;

 	if (origin != SEEK_SET)
 		BUG("rpc_seek only handles SEEK_SET, not %d", origin);
@@ -797,14 +811,15 @@ struct rpc_in_data {
 };

 /*
- * A callback for CURLOPT_WRITEFUNCTION. The return value is the bytes consumed
- * from ptr.
+ * CURLOPT_WRITEFUNCTION callback, called when more received data has come in.
+ * Has the same semantics as fwrite(), but writes packets to the pipe to the
+ * child process instead. The return value is the bytes consumed from ptr.
  */
 static size_t rpc_in(char *ptr, size_t eltsize,
-		size_t nmemb, void *buffer_)
+		size_t nmemb, void *userdata)
 {
 	size_t size = eltsize * nmemb;
-	struct rpc_in_data *data = buffer_;
+	struct rpc_in_data *data = userdata;
 	long response_code;

 	if (curl_easy_getinfo(data->slot->curl, CURLINFO_RESPONSE_CODE,
-- 
2.42.1.5.g2f21867bd5

  parent reply	other threads:[~2023-11-15  3:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-13 11:25 [PATCH] remote-curl: avoid hang if curl asks for more data after eof Jiří Hruška
2023-11-13 21:22 ` Jonathan Tan
2023-11-14  1:36   ` Junio C Hamano
2023-11-14 23:33     ` Jiří Hruška
2023-11-27 13:19       ` Jiří Hruška
2023-11-14 23:16   ` Jiří Hruška
2023-11-15  3:34 ` [PATCH v2 0/5] Avoid hang if curl needs eof twice + minor related improvements Jiří Hruška
2023-11-15 23:28   ` Jonathan Tan
2023-11-27 13:39     ` Jiří Hruška
2023-11-27 18:26       ` Jonathan Tan
     [not found] ` <20231115033121.939-1-jirka@fud.cz>
2023-11-15  3:34   ` [PATCH v2 1/5] remote-curl: avoid hang if curl asks for more data after eof Jiří Hruška
2023-11-15 19:20     ` Jonathan Tan
2023-11-15  3:34   ` Jiří Hruška [this message]
2023-11-15  3:34   ` [PATCH v2 3/5] remote-curl: simplify rpc_out() - remove superfluous ifs Jiří Hruška
2023-11-15  3:34   ` [PATCH v2 4/5] remote-curl: simplify rpc_out() - less nesting and rename Jiří Hruška
2023-11-15  3:34   ` [PATCH v2 5/5] http: reset CURLOPT_POSTFIELDSIZE_LARGE between requests Jiří Hruška
2023-11-15  6:44     ` Patrick Steinhardt
2023-11-27 13:21       ` Jiří Hruška

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGE_+C6ukSe-XTS2x8j3QDJ96yMib7kOtMbcrXes4zNbix0Oyg@mail.gmail.com \
    --to=jirka@fud.cz \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).