[mod_cgi] skip local-redir handling if to self (fixes #2779, #2108)
[lighttpd.git] / src / network_solaris_sendfilev.c
blob697d43f4985796a10579c4b6d33e913355594ff5
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 case EINVAL:
60 case ENOSYS:
61 #if defined(ENOTSUP) \
62 && (!defined(EOPNOTSUPP) || EOPNOTSUPP != ENOTSUP)
63 case ENOTSUP:
64 #endif
65 #ifdef EOPNOTSUPP
66 case EOPNOTSUPP:
67 #endif
68 #ifdef ESOCKTNOSUPPORT
69 case ESOCKTNOSUPPORT:
70 #endif
71 #ifdef EAFNOSUPPORT
72 case EAFNOSUPPORT:
73 #endif
74 #ifdef USE_MMAP
75 return network_write_file_chunk_mmap(srv, con, fd, cq, p_max_bytes);
76 #else
77 return network_write_file_chunk_no_mmap(srv, con, fd, cq, p_max_bytes);
78 #endif
79 default:
80 log_error_write(srv, __FILE__, __LINE__, "ssd", "sendfile: ", strerror(errno), errno);
81 return -1;
85 if (written >= 0) {
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 */