Annotation of embedaddon/lighttpd/src/network_darwin_sendfile.c, revision 1.1.1.1
1.1 misho 1: #include "first.h"
2:
3: #include "network_backends.h"
4:
5: #if defined(USE_DARWIN_SENDFILE)
6:
7: #include "network.h"
8: #include "log.h"
9:
10: #include <sys/types.h>
11: #include <sys/socket.h>
12: #include <sys/uio.h>
13:
14: #include <errno.h>
15: #include <string.h>
16:
17: int network_write_file_chunk_sendfile(server *srv, connection *con, int fd, chunkqueue *cq, off_t *p_max_bytes) {
18: chunk* const c = cq->first;
19: off_t offset, written = 0;
20: off_t toSend;
21: int r;
22:
23: force_assert(NULL != c);
24: force_assert(FILE_CHUNK == c->type);
25: force_assert(c->offset >= 0 && c->offset <= c->file.length);
26:
27: offset = c->file.start + c->offset;
28: toSend = c->file.length - c->offset;
29: if (toSend > *p_max_bytes) toSend = *p_max_bytes;
30:
31: if (0 == toSend) {
32: chunkqueue_remove_finished_chunks(cq);
33: return 0;
34: }
35:
36: if (0 != network_open_file_chunk(srv, con, cq)) return -1;
37:
38: /* Darwin sendfile() */
39: written = toSend;
40: if (-1 == (r = sendfile(c->file.fd, fd, offset, &written, NULL, 0))) {
41: switch(errno) {
42: case EAGAIN:
43: case EINTR:
44: /* for EAGAIN/EINTR written still contains the sent bytes */
45: break; /* try again later */
46: case EPIPE:
47: case ENOTCONN:
48: return -2;
49: case EINVAL:
50: case ENOSYS:
51: #if defined(ENOTSUP) \
52: && (!defined(EOPNOTSUPP) || EOPNOTSUPP != ENOTSUP)
53: case ENOTSUP:
54: #endif
55: #ifdef EOPNOTSUPP
56: case EOPNOTSUPP:
57: #endif
58: #ifdef ESOCKTNOSUPPORT
59: case ESOCKTNOSUPPORT:
60: #endif
61: #ifdef EAFNOSUPPORT
62: case EAFNOSUPPORT:
63: #endif
64: #ifdef USE_MMAP
65: return network_write_file_chunk_mmap(srv, con, fd, cq, p_max_bytes);
66: #else
67: return network_write_file_chunk_no_mmap(srv, con, fd, cq, p_max_bytes);
68: #endif
69: default:
70: log_error_write(srv, __FILE__, __LINE__, "ssd", "sendfile: ", strerror(errno), errno);
71: return -1;
72: }
73: }
74:
75: if (written >= 0) {
76: chunkqueue_mark_written(cq, written);
77: *p_max_bytes -= written;
78: }
79:
80: return (r >= 0 && written == toSend) ? 0 : -3;
81: }
82:
83: #endif /* USE_DARWIN_SENDFILE */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>