3 #include "network_backends.h"
5 #if defined(USE_SOLARIS_SENDFILEV)
10 #include <sys/sendfile.h>
16 * a very simple sendfilev() interface for solaris which can be optimised a lot more
17 * as solaris sendfilev() supports 'sending everythin in one syscall()'
20 int network_write_file_chunk_sendfile(server
*srv
, connection
*con
, int fd
, chunkqueue
*cq
, off_t
*p_max_bytes
) {
21 chunk
* const c
= cq
->first
;
28 force_assert(NULL
!= c
);
29 force_assert(FILE_CHUNK
== c
->type
);
30 force_assert(c
->offset
>= 0 && c
->offset
<= c
->file
.length
);
32 offset
= c
->file
.start
+ c
->offset
;
33 toSend
= c
->file
.length
- c
->offset
;
34 if (toSend
> *p_max_bytes
) toSend
= *p_max_bytes
;
37 chunkqueue_remove_finished_chunks(cq
);
41 if (0 != network_open_file_chunk(srv
, con
, cq
)) return -1;
43 fvec
.sfv_fd
= c
->file
.fd
;
45 fvec
.sfv_off
= offset
;
46 fvec
.sfv_len
= toSend
;
48 /* Solaris sendfilev() */
50 if (-1 == (r
= sendfilev(fd
, &fvec
, 1, &written
))) {
54 /* for EAGAIN/EINTR written still contains the sent bytes */
55 break; /* try again later */
61 #if defined(ENOTSUP) \
62 && (!defined(EOPNOTSUPP) || EOPNOTSUPP != ENOTSUP)
68 #ifdef ESOCKTNOSUPPORT
75 return network_write_file_chunk_mmap(srv
, con
, fd
, cq
, p_max_bytes
);
77 return network_write_file_chunk_no_mmap(srv
, con
, fd
, cq
, p_max_bytes
);
80 log_error_write(srv
, __FILE__
, __LINE__
, "ssd", "sendfile: ", strerror(errno
), errno
);
86 chunkqueue_mark_written(cq
, written
);
87 *p_max_bytes
-= written
;
90 return (r
>= 0 && (off_t
) written
== toSend
) ? 0 : -3;
93 #endif /* USE_SOLARIS_SENDFILEV */