src/server/util/io.c

branch
webdav
changeset 251
f727a21497bb
parent 235
4990147c58d0
child 332
6f82ede01e1c
equal deleted inserted replaced
250:f4d93355b054 251:f727a21497bb
280 280
281 ssize_t net_http_writev(HttpStream *st, struct iovec *iovec, int iovcnt) { 281 ssize_t net_http_writev(HttpStream *st, struct iovec *iovec, int iovcnt) {
282 IOStream *fd = st->fd; 282 IOStream *fd = st->fd;
283 if(st->chunked_enc) { 283 if(st->chunked_enc) {
284 struct iovec *io = calloc(iovcnt + 1, sizeof(struct iovec)); 284 struct iovec *io = calloc(iovcnt + 1, sizeof(struct iovec));
285 if(!io) {
286 return 0;
287 }
285 char chunk_len[16]; 288 char chunk_len[16];
286 io[0].iov_base = chunk_len; 289 io[0].iov_base = chunk_len;
287 size_t len = 0; 290 size_t len = 0;
288 for(int i=0;i<iovcnt;i++) { 291 for(int i=0;i<iovcnt;i++) {
289 len += iovec[i].iov_len; 292 len += iovec[i].iov_len;
290 } 293 }
291 io[0].iov_len = snprintf(chunk_len, 16, "\r\n%zx\r\n", len); 294 io[0].iov_len = snprintf(chunk_len, 16, "\r\n%zx\r\n", len);
292 memcpy(io + 1, iovec, iovcnt * sizeof(struct iovec)); 295 memcpy(io + 1, iovec, iovcnt * sizeof(struct iovec));
293 ssize_t r = fd->writev(fd, io, iovcnt + 1); 296 ssize_t r = fd->writev(fd, io, iovcnt + 1);
294 return r - io[0].iov_len; 297
298 ssize_t ret = r - io[0].iov_len;
299 free(io);
300 return ret;
295 } else { 301 } else {
296 return fd->writev(fd, iovec, iovcnt); 302 return fd->writev(fd, iovec, iovcnt);
297 } 303 }
298 } 304 }
299 305

mercurial