~ubuntu-branches/ubuntu/saucy/lighttpd/saucy

« back to all changes in this revision

Viewing changes to src/network_freebsd_sendfile.c

  • Committer: Package Import Robot
  • Author(s): Lorenzo De Liso
  • Date: 2012-12-06 17:54:59 UTC
  • mfrom: (6.1.20 sid)
  • Revision ID: package-import@ubuntu.com-20121206175459-aq6vz5xa9fa202jw
Tags: 1.4.31-3ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: libgamin-dev rather than libfam-dev to fix startup warning.
  - debian/index.html: s/Debian/Ubuntu/g branding on the default page.
  - Added a UFW profile set:
    + debian/lighttpd.dirs: added etc/ufw/applications.d
    + debian/rules: install the ufw profile.
    + debian/control: Suggests on ufw.
  - Add lighttpd-dev package:
    + debian/control: Added lighttpd-dev package; Build-depends on
      automake, libtool
    + debian/lighttpd-dev.install: Added.
  - debian/rules: Add override_dh_installinit to set "defaults 91 09" to not
    start before apache2 but in the same runlevel with the same priority.
  - debian/patches/build-dev-package.patch: Updated
  - debian/lighttpd.conf: Comment 'use-ipv6.pl' by default, which causes
    failure to bind port in ipv4
* debian/index.html: corrected BTS Ubuntu link for lighttpd

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
# endif
32
32
#endif
33
33
 
34
 
int network_write_chunkqueue_freebsdsendfile(server *srv, connection *con, int fd, chunkqueue *cq) {
 
34
int network_write_chunkqueue_freebsdsendfile(server *srv, connection *con, int fd, chunkqueue *cq, off_t max_bytes) {
35
35
        chunk *c;
36
 
        size_t chunks_written = 0;
37
36
 
38
 
        for(c = cq->first; c; c = c->next, chunks_written++) {
 
37
        for(c = cq->first; (max_bytes > 0) && (NULL != c); c = c->next) {
39
38
                int chunk_finished = 0;
40
39
 
41
40
                switch(c->type) {
42
41
                case MEM_CHUNK: {
43
42
                        char * offset;
44
 
                        size_t toSend;
 
43
                        off_t toSend;
45
44
                        ssize_t r;
46
45
 
47
46
                        size_t num_chunks, i;
49
48
                        chunk *tc;
50
49
                        size_t num_bytes = 0;
51
50
 
52
 
                        /* we can't send more then SSIZE_MAX bytes in one chunk */
53
 
 
54
51
                        /* build writev list
55
52
                         *
56
53
                         * 1. limit: num_chunks < UIO_MAXIOV
57
 
                         * 2. limit: num_bytes < SSIZE_MAX
 
54
                         * 2. limit: num_bytes < max_bytes
58
55
                         */
59
56
                        for(num_chunks = 0, tc = c; tc && tc->type == MEM_CHUNK && num_chunks < UIO_MAXIOV; num_chunks++, tc = tc->next);
60
57
 
69
66
                                        chunks[i].iov_base = offset;
70
67
 
71
68
                                        /* protect the return value of writev() */
72
 
                                        if (toSend > SSIZE_MAX ||
73
 
                                            num_bytes + toSend > SSIZE_MAX) {
74
 
                                                chunks[i].iov_len = SSIZE_MAX - num_bytes;
 
69
                                        if (toSend > max_bytes ||
 
70
                                            (off_t) num_bytes + toSend > max_bytes) {
 
71
                                                chunks[i].iov_len = max_bytes - num_bytes;
75
72
 
76
73
                                                num_chunks = i + 1;
77
74
                                                break;
105
102
 
106
103
                        /* check which chunks have been written */
107
104
                        cq->bytes_out += r;
 
105
                        max_bytes -= r;
108
106
 
109
107
                        for(i = 0, tc = c; i < num_chunks; i++, tc = tc->next) {
110
108
                                if (r >= (ssize_t)chunks[i].iov_len) {
114
112
 
115
113
                                        if (chunk_finished) {
116
114
                                                /* skip the chunks from further touches */
117
 
                                                chunks_written++;
118
115
                                                c = c->next;
119
116
                                        } else {
120
117
                                                /* chunks_written + c = c->next is done in the for()*/
121
 
                                                chunk_finished++;
 
118
                                                chunk_finished = 1;
122
119
                                        }
123
120
                                } else {
124
121
                                        /* partially written */
134
131
                }
135
132
                case FILE_CHUNK: {
136
133
                        off_t offset, r;
137
 
                        size_t toSend;
 
134
                        off_t toSend;
138
135
                        stat_cache_entry *sce = NULL;
139
136
 
140
137
                        if (HANDLER_ERROR == stat_cache_get_entry(srv, con, c->file.name, &sce)) {
144
141
                        }
145
142
 
146
143
                        offset = c->file.start + c->offset;
147
 
                        /* limit the toSend to 2^31-1 bytes in a chunk */
148
 
                        toSend = c->file.length - c->offset > ((1 << 30) - 1) ?
149
 
                                ((1 << 30) - 1) : c->file.length - c->offset;
 
144
                        toSend = c->file.length - c->offset;
 
145
                        if (toSend > max_bytes) toSend = max_bytes;
150
146
 
151
147
                        if (-1 == c->file.fd) {
152
148
                                if (-1 == (c->file.fd = open(c->file.name->ptr, O_RDONLY))) {
197
193
 
198
194
                        c->offset += r;
199
195
                        cq->bytes_out += r;
 
196
                        max_bytes -= r;
200
197
 
201
198
                        if (c->offset == c->file.length) {
202
199
                                chunk_finished = 1;
218
215
                }
219
216
        }
220
217
 
221
 
        return chunks_written;
 
218
        return 0;
222
219
}
223
220
 
224
221
#endif