[core] set REDIRECT_STATUS to error_handler_saved_status (fixes #1828)
[lighttpd.git] / src / network_solaris_sendfilev.c
blob17a36b1ec319e922973793fc3ac854a89a479d03
1 #include "first.h"
3 #include "network_backends.h"
5 #if defined(USE_SOLARIS_SENDFILEV)
7 #include "network.h"
8 #include "log.h"
10 #include <sys/sendfile.h>
12 #include <errno.h>
13 #include <string.h>
15 /**
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;
22 off_t offset;
23 off_t toSend;
24 size_t written = 0;
25 int r;
26 sendfilevec_t fvec;
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;
36 if (0 == toSend) {
37 chunkqueue_remove_finished_chunks(cq);
38 return 0;
41 if (0 != network_open_file_chunk(srv, con, cq)) return -1;
43 fvec.sfv_fd = c->file.fd;
44 fvec.sfv_flag = 0;
45 fvec.sfv_off = offset;
46 fvec.sfv_len = toSend;
48 /* Solaris sendfilev() */
50 if (-1 == (r = sendfilev(fd, &fvec, 1, &written))) {
51 switch(errno) {
52 case EAGAIN:
53 case EINTR:
54 /* for EAGAIN/EINTR written still contains the sent bytes */
55 break; /* try again later */
56 case EPIPE:
57 case ENOTCONN:
58 return -2;
59 default:
60 log_error_write(srv, __FILE__, __LINE__, "ssd", "sendfile: ", strerror(errno), errno);
61 return -1;
65 if (written >= 0) {
66 chunkqueue_mark_written(cq, written);
67 *p_max_bytes -= written;
70 return (r >= 0 && (off_t) written == toSend) ? 0 : -3;
73 #endif /* USE_SOLARIS_SENDFILEV */