From: Junio C Hamano <gitster@pobox.com>
To: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Cc: git@vger.kernel.org
Subject: Re: [RFC PATCH v6 1/3] Add bidirectional_transfer_loop()
Date: Mon, 11 Oct 2010 20:57:13 -0700 [thread overview]
Message-ID: <7v1v7woyg6.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: 1286571713-7755-2-git-send-email-ilari.liusvaara@elisanet.fi
Ilari Liusvaara <ilari.liusvaara@elisanet.fi> writes:
> This helper function copies bidirectional stream of data between
> stdin/stdout and specified file descriptors.
>
> Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
> ---
> diff --git a/transport-helper.c b/transport-helper.c
> index acfc88e..acbae47 100644
> --- a/transport-helper.c
> +++ b/transport-helper.c
> @@ -862,3 +862,264 @@ int transport_helper_init(struct transport *transport, const char *name)
> + ...
> +static int udt_do_read(struct unidirectional_transfer *t)
> +{
> + int r;
> + transfer_debug("%s is readable", t->src_name);
> + r = read(t->src, t->buf + t->bufuse, BUFFERSIZE - t->bufuse);
> + if (r < 0 && errno != EWOULDBLOCK && errno != EAGAIN &&
> + errno != EINTR) {
> + error("read(%s) failed: %s", t->src_name, strerror(errno));
> + return -1;
> + } else if (r == 0) {
> + transfer_debug("%s EOF (with %i bytes in buffer)",
> + t->src_name, t->bufuse);
> + t->state = SSTATE_FLUSHING;
> + } else if (r > 0) {
> + t->bufuse += r;
> + transfer_debug("Read %i bytes from %s (buffer now at %i)",
> + r, t->src_name, (int)t->bufuse);
> + }
> + return 0;
> +}
This is probably a stupid question, but can t->bufuse be equal to BUFFERSIZE
when this function is entered? What happens in such a case?
You would want to rename the counter "count" or "bytes" or somesuch if you
want to copy & paste it to udt_do_write() side, as "int r" that holds the
number of bytes _written_ feels somewhat odd ;-).
> +static int udt_do_write(struct unidirectional_transfer *t)
> +{
> + int r;
> + transfer_debug("%s is writable", t->dest_name);
> + r = write(t->dest, t->buf, t->bufuse);
> + if (r < 0 && errno != EWOULDBLOCK && errno != EAGAIN &&
> ...
> +#ifndef NO_PTHREADS
> +static int transloop_with_threads(struct bidirectional_transfer_state *s)
> +{
> + pthread_t gtp_thread;
> + pthread_t ptg_thread;
> + int err;
> + int ret = 0;
> + void *dummy;
> + err = pthread_create(>p_thread, NULL, udt_copy_thread_routine,
> + &s->gtp);
> + if (err)
> + die("Can't start thread for copying data: %s", strerror(err));
> + err = pthread_create(&ptg_thread, NULL, udt_copy_thread_routine,
> + &s->ptg);
> + if (err)
> + die("Can't start thread for copying data: %s", strerror(err));
> + err = pthread_join(gtp_thread, &dummy);
> + if (!dummy) {
I suspect that originally you did not use "dummy" for anything, but if you
use the value to decide what to do, it now probably is something more than
a dummy, no?
Just out of curiosity, does the order of creation and joining of these
threads make a difference?
> + error("Git to program copy thread failed");
> + ret = 1;
> + }
> ...
> +#else
> +
> +static void udt_kill_transfer(struct unidirectional_transfer *t)
> +{
> + t->state = SSTATE_FINISHED;
> + close(t->src);
> + if (t->dest_is_sock)
> + shutdown(t->dest, SHUT_WR);
> + else
> + close(t->dest);
> +}
> +
> +static int transloop_with_threads(struct bidirectional_transfer_state *s)
> +{
It feels funny to see in NO_PTHREADS codepath a something_with_threads
function that uses fork(). Perhaps bidirectional_transfer_loop() can call
a function with a more generic name, e.g. transloop(), that is implemented
in terms of either threads or processes depending on the platform
capability?
next prev parent reply other threads:[~2010-10-12 3:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-08 21:01 [RFC PATCH v6 0/3] git-remote-fd & git-remote-ext Ilari Liusvaara
2010-10-08 21:01 ` [RFC PATCH v6 1/3] Add bidirectional_transfer_loop() Ilari Liusvaara
2010-10-12 3:57 ` Junio C Hamano [this message]
2010-10-08 21:01 ` [RFC PATCH v6 2/3] git-remote-fd Ilari Liusvaara
2010-10-08 21:01 ` [RFC PATCH v6 3/3] git-remote-ext Ilari Liusvaara
2010-10-08 22:02 ` Jonathan Nieder
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v1v7woyg6.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).