rework zm_sendfile to try again if not all bytes were sent. According to the docs, this is entirely possible.
This commit is contained in:
parent
88a68af775
commit
0da942a14b
|
@ -3,22 +3,25 @@
|
||||||
|
|
||||||
#ifdef HAVE_SENDFILE4_SUPPORT
|
#ifdef HAVE_SENDFILE4_SUPPORT
|
||||||
#include <sys/sendfile.h>
|
#include <sys/sendfile.h>
|
||||||
int zm_sendfile(int out_fd, int in_fd, off_t *offset, size_t size) {
|
ssize_t zm_sendfile(int out_fd, int in_fd, off_t *offset, size_t size) {
|
||||||
int err;
|
size_t remaining = size;
|
||||||
|
while (remaining) {
|
||||||
err = sendfile(out_fd, in_fd, offset, size);
|
ssize_t err = sendfile(out_fd, in_fd, offset, remaining);
|
||||||
if ( err < 0 )
|
if (err < 0) {
|
||||||
return -errno;
|
return -errno;
|
||||||
|
}
|
||||||
|
remaining -= err;
|
||||||
|
offset += err;
|
||||||
|
}
|
||||||
|
|
||||||
return err;
|
return size-remaining;
|
||||||
}
|
}
|
||||||
#elif HAVE_SENDFILE7_SUPPORT
|
#elif HAVE_SENDFILE7_SUPPORT
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
int zm_sendfile(int out_fd, int in_fd, off_t *offset, off_t size) {
|
ssize_t zm_sendfile(int out_fd, int in_fd, off_t *offset, off_t size) {
|
||||||
int err;
|
ssize_t err = sendfile(in_fd, out_fd, *offset, size, nullptr, &size, 0);
|
||||||
err = sendfile(in_fd, out_fd, *offset, size, nullptr, &size, 0);
|
|
||||||
if (err && errno != EAGAIN)
|
if (err && errno != EAGAIN)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue