From: Eric Dumazet <eric.dumazet@gmail.com>
To: Ulrich Drepper <drepper@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: sendfile and EAGAIN
Date: Mon, 25 Feb 2013 11:22:55 -0800 [thread overview]
Message-ID: <1361820175.6781.13.camel@edumazet-glaptop> (raw)
In-Reply-To: <CAOPLpQcs5GgVRqXhnxF0Ui0k-39-xX5N2nYWYY4DhVWMYCMQ7w@mail.gmail.com>
On Mon, 2013-02-25 at 12:22 -0500, Ulrich Drepper wrote:
> When using sendfile with a non-blocking output file descriptor for a
> socket the operation can cause a partial write because of capacity
> issues. This is nothing critical and the operation could resume after
> the output queue is cleared. The problem is: there is no way to
> determine where to resume.
>
> The system call just returns -EAGAIN without any further indication.
> The caller doesn't know what to resend.
>
> And this even though the interface of sendfile would be capable of
> communicating this information and the man page (I know, it's not
> authoritive) describes this behavior as well.
>
> The problem is probably in a few places, here is one (fs/splice.c):
>
> static ssize_t default_file_splice_write(struct pipe_inode_info *pipe,
> struct file *out, loff_t *ppos,
> size_t len, unsigned int flags)
> {
> ssize_t ret;
>
> ret = splice_from_pipe(pipe, out, ppos, len, flags, write_pipe_buf);
> if (ret > 0)
> *ppos += ret;
>
> return ret;
> }
>
> Note that *ppos is only updated if the call doesn't fail. We could
> also update the position if ret == -EAGAIN. This would require
> re-architecting the system a bit to either update *ppos in
> splice_from_pipe etc or to communicate number of the bytes which are
> written from the splice_from_pipe call. In any case, the result would
> be that the caller knows where to resume the operation.
>
> I would argue that this doesn't break the ABI. In case existing
> programs today just resend packages today from the beginning they will
> have send an unpredictable number of bytes in the previous sendfile()
> call, making the state of the communication unpredictable.
>
> Opinions? I think as is sendfile() isn't useful with O_NONBLOCK.
> --
I don't understand the issue.
sendfile() returns -EAGAIN only if no bytes were copied to the socket.
If some bytes were copied, sendfile() returns the number of bytes,
exactly like write() would do for a partial write.
I guess the following should work (well... with better tests)
offset = 0;
while (offset < len) {
res = sendfile(sock, fd, &offset, len - offset);
if (res >= 0) {
offset += res;
} else {
if (errno != EAGAIN)
break;
wait_some_event();
}
}
next prev parent reply other threads:[~2013-02-25 19:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-25 17:22 Ulrich Drepper
2013-02-25 19:22 ` Eric Dumazet [this message]
2013-03-03 1:41 ` Ulrich Drepper
2013-03-03 3:09 ` Eric Dumazet
2013-03-03 3:16 ` Ulrich Drepper
2013-03-04 10:28 ` Eric Wong
2013-03-05 0:11 ` Ulrich Drepper
2013-03-03 3:53 ` H. Peter Anvin
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=1361820175.6781.13.camel@edumazet-glaptop \
--to=eric.dumazet@gmail.com \
--cc=drepper@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®