src/server/util/io.c

branch
webdav
changeset 336
fb75473fecca
parent 335
5234c57b8759
child 354
017eda1be105
equal deleted inserted replaced
335:5234c57b8759 336:fb75473fecca
266 HttpStream *http = (HttpStream*)st; 266 HttpStream *http = (HttpStream*)st;
267 http->max_read = 0; 267 http->max_read = 0;
268 http->read = 0; 268 http->read = 0;
269 http->readbuf = buffer; 269 http->readbuf = buffer;
270 http->bufsize = bufsize; 270 http->bufsize = bufsize;
271 http->buflen = *cursize; // TODO: store buflen as pointer 271 http->buflen = cursize;
272 http->bufpos = pos; 272 http->bufpos = pos;
273 http->chunk_buf_pos = 0; 273 http->chunk_buf_pos = 0;
274 return 0; 274 return 0;
275 } 275 }
276 276
362 //memset(buf, 'x', nbytes); 362 //memset(buf, 'x', nbytes);
363 //char *orig_buf = buf; 363 //char *orig_buf = buf;
364 364
365 // copy available data from st->readbuf to buf 365 // copy available data from st->readbuf to buf
366 int pos = *st->bufpos; 366 int pos = *st->bufpos;
367 size_t buf_available = st->buflen - pos; 367 size_t buf_available = *st->buflen - pos;
368 if(buf_available) { 368 if(buf_available) {
369 size_t cplen = buf_available > nbytes ? nbytes : buf_available; 369 size_t cplen = buf_available > nbytes ? nbytes : buf_available;
370 if(read_data) { 370 if(read_data) {
371 // if we read data (and not a chunk header), we limit the 371 // if we read data (and not a chunk header), we limit the
372 // amount of bytes we copy 372 // amount of bytes we copy
387 // 387 //
388 // if we read a chunk header (read_data == false) it is very important 388 // if we read a chunk header (read_data == false) it is very important
389 // to not perform IO, if we have previously copied data from readbuf 389 // to not perform IO, if we have previously copied data from readbuf
390 // this ensures we never override non-chunk-header data 390 // this ensures we never override non-chunk-header data
391 if(*perform_io && ((read_data && nbytes > 0 && st->max_read - st->read) || (!read_data && r == 0))) { 391 if(*perform_io && ((read_data && nbytes > 0 && st->max_read - st->read) || (!read_data && r == 0))) {
392 if(st->buflen - *st->bufpos > 0) { 392 if(*st->buflen - *st->bufpos > 0) {
393 printf("todo: fix, should not happen, remove later\n"); 393 printf("todo: fix, should not happen, remove later\n");
394 } 394 }
395 // fill buffer again 395 // fill buffer again
396 ssize_t rlen = st->fd->read(st->fd, st->readbuf, st->bufsize); 396 ssize_t rlen = st->fd->read(st->fd, st->readbuf, st->bufsize);
397 st->buflen = rlen; 397 *st->buflen = rlen;
398 *st->bufpos = 0; 398 *st->bufpos = 0;
399 *perform_io = WS_FALSE; 399 *perform_io = WS_FALSE;
400 if(rlen < 0) { 400 if(rlen < 0) {
401 st->st.io_errno = st->fd->io_errno; 401 st->st.io_errno = st->fd->io_errno;
402 } 402 }

mercurial