From: Jonathan Nieder <jrnieder@gmail.com>
To: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v4 1/3] Add bidirectional_transfer_loop()
Date: Mon, 4 Oct 2010 06:19:04 -0500 [thread overview]
Message-ID: <20101004111904.GC4738@burratino> (raw)
In-Reply-To: <1286190258-12724-2-git-send-email-ilari.liusvaara@elisanet.fi>
Ilari Liusvaara wrote:
> --- a/transport-helper.c
> +++ b/transport-helper.c
> @@ -862,3 +862,327 @@ int transport_helper_init(struct transport *transport, const char *name)
[...]
> +/* Unidirectional transfer. */
> +struct unidirectional_transfer
> +{
> + int src;
> + int dest;
> + int dest_is_sock;
> + int state;
> + char buf[BUFFERSIZE];
> + size_t bufuse;
> + const char *src_name;
> + const char *dest_name;
> +};
Nice. :)
(I would have written
int src;
int dest
unsigned dest_is_sock:1;
enum unidirectional_transfer_state state;
char buf[BUFFERSIZE];
...
to make the types more obvious, but I think that's more of a matter of
style.)
[...]
> +/* State of bidirectional transfer loop. */
> +struct bidirectional_transfer_state
> +{
> + struct pollfd polls[4];
> + int polls_active;
> + int stdin_index;
> + int stdout_index;
> + int input_index;
> + int output_index;
> + /* Direction from program to git. */
> + struct unidirectional_transfer ptg;
> + /* Direction from git to program. */
> + struct unidirectional_transfer gtp;
> +};
Sensible.
> +int bidirectional_transfer_loop(int input, int output)
> +{
> + struct bidirectional_transfer_state state;
> +
> + /* Fill the state fields. */
> + state.ptg.src = input;
> + state.ptg.dest = 1;
> + state.ptg.dest_is_sock = 0;
> + state.ptg.state = SSTATE_TRANSFERING;
> + state.ptg.bufuse = 0;
> + state.ptg.src_name = "remote input";
> + state.ptg.dest_name = "stdout";
> +
> + state.gtp.src = 0;
> + state.gtp.dest = output;
> + state.gtp.dest_is_sock = (input == output);
> + state.gtp.state = SSTATE_TRANSFERING;
> + state.gtp.bufuse = 0;
> + state.gtp.src_name = "stdin";
> + state.gtp.dest_name = "remote output";
> +
> + while (1) {
> + int r;
> + load_poll_params(&state);
> + if (!state.polls_active) {
> + transfer_debug("Transfer done");
> + break;
> + }
> + transfer_debug("Waiting for %i file descriptors",
> + state.polls_active);
> + r = poll(state.polls, state.polls_active, -1);
> + if (r < 0) {
> + if (errno == EWOULDBLOCK || errno == EAGAIN ||
> + errno == EINTR)
> + continue;
> + error("poll failed: %s", strerror(errno));
> + return -1;
> + } else if (r == 0)
> + continue;
> +
> + r = transfer_handle_events(&state);
> + if (r)
> + return r;
> + }
> + return 0;
> +}
Yes, that's much clearer.
Linux's scripts/checkpatch.pl would have a few things to say, but
I have no complaint myself except the density of comments (which is a
matter of taste).
Thanks!
next prev parent reply other threads:[~2010-10-04 11:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-04 11:04 [PATCH v4 0/3] git-remote-fd & git-remote-ext Ilari Liusvaara
2010-10-04 11:04 ` [PATCH v4 1/3] Add bidirectional_transfer_loop() Ilari Liusvaara
2010-10-04 11:19 ` Jonathan Nieder [this message]
2010-10-04 11:04 ` [PATCH v4 2/3] git-remote-fd Ilari Liusvaara
2010-10-04 11:25 ` Jonathan Nieder
2010-10-07 5:55 ` Junio C Hamano
2010-10-04 11:04 ` [PATCH v4 3/3] git-remote-ext Ilari Liusvaara
2010-10-04 16:56 ` Sverre Rabbelier
2010-10-04 18:11 ` Ilari Liusvaara
2010-10-04 18:09 ` Sverre Rabbelier
2010-10-04 11:30 ` [PATCH v4 0/3] git-remote-fd & git-remote-ext Jonathan Nieder
2010-10-04 12:06 ` Ilari Liusvaara
2010-10-04 12:28 ` yj2133011
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=20101004111904.GC4738@burratino \
--to=jrnieder@gmail.com \
--cc=git@vger.kernel.org \
--cc=ilari.liusvaara@elisanet.fi \
/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).