git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Cc: git@vger.kernel.org
Subject: Re: [RFC PATCH v3 5/8] Support taking over transports
Date: Mon, 7 Dec 2009 09:49:47 -0800	[thread overview]
Message-ID: <20091207174947.GF17173@spearce.org> (raw)
In-Reply-To: <1260116931-16549-6-git-send-email-ilari.liusvaara@elisanet.fi>

Ilari Liusvaara <ilari.liusvaara@elisanet.fi> wrote:
> @@ -109,9 +120,21 @@ static struct child_process *get_helper(struct transport *transport)
>  		die("Unable to run helper: git %s", helper->argv[0]);
>  	data->helper = helper;
>  
> +	/* Open the output as FILE* so strbuf_getline() can be used.
> +	   Do this with duped fd because fclose() will close the fd,
> +	   and stuff like disowning will require the fd to remain.
> +
> +	   Set the stream to unbuffered because some reads are critical
> +	   in sense that any overreading will cause deadlocks.
> +	*/
> +        duped = dup(helper->out);

Formatting error here, the line is indented wrong.

> +	if (duped < 0)
> +		die_errno("Can't dup helper output fd");
> +	data->out = xfdopen(duped, "r");
> +	setvbuf(data->out, NULL, _IONBF, 0);

I wonder if this is really a good idea.  Most helpers actually
use a lot of text based IO to communicate.  Disabling buffering
for those helpers to avoid overreading the advertisement from a
connect is a problem.

Maybe we could leave buffering on, but use a handshake protocol
with the helper during connect:

  (1) > "connect git-upload-pack\n"
  (2) < "\n"
  (3) > "begin\n"

During 2 we are still buffered, but the only content on the pipe
should be the single blank line, so we pull that in and the FILE*
buffer should be empty.

After writing message 2 the remote helper blocks reading for the
"begin\n" message 3.  This gives the transport-helper.c code time
to switch off the FILE* and start using raw IO off the pipe before
any data starts coming down the line.

It does mean that the helper may need to run unbuffered IO, but
if the helper is only a smart helper supporting connect then this
isn't really a problem.  It can run buffered IO until connect is
received, switch to unbuffered, and use unbuffered for the single
"begin\n" message it has to consume before it starts writing output
or reading input.

-- 
Shawn.

  reply	other threads:[~2009-12-07 17:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-06 16:28 [RFC PATCH v3 0/8] Remote helpers smart transport extensions Ilari Liusvaara
2009-12-06 16:28 ` [RFC PATCH v3 1/8] Add remote helper debug mode Ilari Liusvaara
2009-12-06 16:28 ` [RFC PATCH v3 2/8] Support mandatory capabilities Ilari Liusvaara
2009-12-06 16:28 ` [RFC PATCH v3 3/8] Pass unknown protocols to external protocol handlers Ilari Liusvaara
2009-12-06 16:28 ` [RFC PATCH v3 4/8] Refactor git transport options parsing Ilari Liusvaara
2009-12-06 16:28 ` [RFC PATCH v3 5/8] Support taking over transports Ilari Liusvaara
2009-12-07 17:49   ` Shawn O. Pearce [this message]
2009-12-07 21:19     ` Ilari Liusvaara
2009-12-06 16:28 ` [RFC PATCH v3 6/8] Support remote helpers implementing smart transports Ilari Liusvaara
2009-12-07 18:11   ` Shawn O. Pearce
2009-12-07 20:35     ` Ilari Liusvaara
2009-12-06 16:28 ` [RFC PATCH v3 7/8] Support remote archive from external protocol helpers Ilari Liusvaara
2009-12-07 18:12   ` Shawn O. Pearce
2009-12-07 20:37     ` Ilari Liusvaara
2009-12-06 16:28 ` [RFC PATCH v3 8/8] Remove special casing of http, https and ftp Ilari Liusvaara
2009-12-07  7:36 ` [RFC PATCH v3 0/8] Remote helpers smart transport extensions Junio C Hamano
2009-12-07 12:06   ` Nanako Shiraishi
2009-12-07 12:57     ` Erik Faye-Lund
2009-12-07 15:44     ` Nicolas Pitre
2009-12-07 20:07     ` Junio C Hamano
2009-12-07 22:25       ` Nanako Shiraishi
2009-12-08  5:57       ` Jeff King
2009-12-08  6:29         ` Jeff King
2009-12-07 16:33   ` Ilari Liusvaara
2009-12-07 20:05     ` Junio C Hamano

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=20091207174947.GF17173@spearce.org \
    --to=spearce@spearce.org \
    --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).