mirror of
https://github.com/samba-team/samba.git
synced 2025-01-12 09:18:10 +03:00
s3: smbd: Fix Solaris sendfile() for SMB2. Ensure we don't spin on EAGAIN.
For SMB2 the socket is set non-blocking. Ensure sendfile() calls complete if they return EAGAIN by saving the socket state, setting it blocking, doing the sendfile until completion and then restoring the socket state. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13537 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
This commit is contained in:
parent
809967b3ea
commit
16a587075c
@ -169,6 +169,9 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset
|
||||
size_t total, xferred;
|
||||
struct sendfilevec vec[2];
|
||||
ssize_t hdr_len = 0;
|
||||
int old_flags = 0;
|
||||
ssize_t ret = -1;
|
||||
bool socket_flags_changed = false;
|
||||
|
||||
if (header) {
|
||||
sfvcnt = 2;
|
||||
@ -205,17 +208,37 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset
|
||||
xferred = 0;
|
||||
|
||||
nwritten = sendfilev(tofd, vec, sfvcnt, &xferred);
|
||||
if (nwritten == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) {
|
||||
if (nwritten == -1 && errno == EINTR) {
|
||||
if (xferred == 0)
|
||||
continue; /* Nothing written yet. */
|
||||
else
|
||||
nwritten = xferred;
|
||||
}
|
||||
|
||||
if (nwritten == -1)
|
||||
return -1;
|
||||
if (nwritten == 0)
|
||||
return -1; /* I think we're at EOF here... */
|
||||
if (nwritten == -1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
/*
|
||||
* Sendfile must complete before we can
|
||||
* send any other outgoing data on the socket.
|
||||
* Ensure socket is in blocking mode.
|
||||
* For SMB2 by default the socket is in
|
||||
* non-blocking mode.
|
||||
*/
|
||||
old_flags = fcntl(tofd, F_GETFL, 0);
|
||||
ret = set_blocking(tofd, true);
|
||||
if (ret == -1) {
|
||||
goto out;
|
||||
}
|
||||
socket_flags_changed = true;
|
||||
continue;
|
||||
}
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
if (nwritten == 0) {
|
||||
ret = -1;
|
||||
goto out; /* I think we're at EOF here... */
|
||||
}
|
||||
|
||||
/*
|
||||
* If this was a short (signal interrupted) write we may need
|
||||
@ -237,7 +260,28 @@ ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset
|
||||
}
|
||||
total -= nwritten;
|
||||
}
|
||||
return count + hdr_len;
|
||||
ret = count + hdr_len;
|
||||
|
||||
out:
|
||||
|
||||
if (socket_flags_changed) {
|
||||
int saved_errno;
|
||||
int err;
|
||||
|
||||
if (ret == -1) {
|
||||
saved_errno = errno;
|
||||
}
|
||||
/* Restore the old state of the socket. */
|
||||
err = fcntl(tofd, F_SETFL, old_flags);
|
||||
if (err == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (ret == -1) {
|
||||
errno = saved_errno;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#elif defined(HPUX_SENDFILE_API)
|
||||
|
Loading…
Reference in New Issue
Block a user