ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:105518] Re: [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream`
Date: Fri, 1 Oct 2021 05:01:48 +0000	[thread overview]
Message-ID: <20211001050148.GB12161@dcvr> (raw)
In-Reply-To: <redmine.journal-93903.20210927201152.7941@ruby-lang.org>

"ioquatix (Samuel Williams)" <noreply@ruby-lang.org> wrote:
> Just FYI: `sendfile` is less flexible and you should generally
> avoid it. The modern syscall is `splice`.

No point in avoiding sendfile, sendfile is considerably easier
to use in common cases and results in fewer syscalls.

splice requires one end to be a pipe; if neither end is a pipe
so you need to create and manage the pipe yourself as an
intermediate buffer.  Basically, instead of:

   void *buf = malloc(...);
   while (read(rfd, buf, ...) > 0)
     write(wfd, buf, ...);
   free(buf);

It becomes:

   int buf[2];
   pipe2(buf, ...);
   while (splice(rfd, ..., buf[1], ...) > 0) /* splice into pipe */
     splice(buf[0], ..., wfd, ...);  /* splice out of pipe */
   close(buf[0]);
   close(buf[1]);

sendfile creates an internal pipe transparently inside the
kernel for doing splice.  The pipe is still there, but private
to the kernel so you won't have to jump between userspace and
kernel space repeatedly.

  reply	other threads:[~2021-10-01  5:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 12:16 [ruby-core:105450] [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream` byroot (Jean Boussier)
2021-09-27 16:57 ` [ruby-core:105451] " Eregon (Benoit Daloze)
2021-10-01  4:48   ` [ruby-core:105517] " Eric Wong
2021-09-27 20:11 ` [ruby-core:105453] " ioquatix (Samuel Williams)
2021-10-01  5:01   ` Eric Wong [this message]
2021-09-27 21:21 ` [ruby-core:105454] " byroot (Jean Boussier)
2021-09-28 10:10 ` [ruby-core:105463] " Eregon (Benoit Daloze)
2021-09-28 10:17 ` [ruby-core:105464] " byroot (Jean Boussier)
2021-09-30 10:02 ` [ruby-core:105502] " ioquatix (Samuel Williams)
2021-09-30 10:09 ` [ruby-core:105503] " byroot (Jean Boussier)
2021-09-30 20:06 ` [ruby-core:105514] " Eregon (Benoit Daloze)

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-list from there: mbox

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

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

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

  git send-email \
    --in-reply-to=20211001050148.GB12161@dcvr \
    --to=ruby-core@ruby-lang.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).