src/server/util/io.c

branch
webdav
changeset 334
a55491f66003
parent 333
bb536d4bc174
child 335
5234c57b8759
equal deleted inserted replaced
333:bb536d4bc174 334:a55491f66003
359 * read from st->chunk_buf first, read from st->fd if perform_io is true 359 * read from st->chunk_buf first, read from st->fd if perform_io is true
360 */ 360 */
361 static ssize_t net_http_read_buffered(HttpStream *st, char *buf, size_t nbytes, WSBool read_data, WSBool *perform_io) { 361 static ssize_t net_http_read_buffered(HttpStream *st, char *buf, size_t nbytes, WSBool read_data, WSBool *perform_io) {
362 ssize_t r = 0; 362 ssize_t r = 0;
363 363
364 //memset(buf, 'x', nbytes);
365 //char *orig_buf = buf;
366
364 // remaining bytes from the chunkbuf 367 // remaining bytes from the chunkbuf
368 /*
365 if(st->remaining_len > 0) { 369 if(st->remaining_len > 0) {
366 size_t cplen = st->remaining_len > nbytes ? nbytes : st->remaining_len; 370 size_t cplen = st->remaining_len > nbytes ? nbytes : st->remaining_len;
367 WSBool ret = FALSE; 371 WSBool ret = FALSE;
368 if(read_data) { 372 if(read_data) {
369 // if we read data (and not a chunk header), we limit the 373 // if we read data (and not a chunk header), we limit the
386 } 390 }
387 if(ret) { 391 if(ret) {
388 return r; 392 return r;
389 } 393 }
390 } 394 }
395 */
391 396
392 // copy available data from st->readbuf to buf 397 // copy available data from st->readbuf to buf
393 int pos = *st->bufpos; 398 int pos = *st->bufpos;
394 size_t buf_available = st->buflen - pos; 399 size_t buf_available = st->buflen - pos;
395 if(buf_available) { 400 if(buf_available) {
406 r += cplen; 411 r += cplen;
407 buf += cplen; 412 buf += cplen;
408 nbytes -= cplen; 413 nbytes -= cplen;
409 } 414 }
410 415
411 if(*perform_io && nbytes > 0) { 416 if(*perform_io && ((read_data && nbytes > 0 && st->max_read - st->read) || (!read_data && r == 0))) {
417 if(st->buflen - *st->bufpos > 0) {
418 printf("todo: fix, should not happen, remove later\n");
419 }
412 // fill buffer again 420 // fill buffer again
413 ssize_t rlen = st->fd->read(st->fd, st->readbuf, st->bufsize); 421 ssize_t rlen = st->fd->read(st->fd, st->readbuf, st->bufsize);
414 st->buflen = rlen; 422 st->buflen = rlen;
415 *st->bufpos = 0; 423 *st->bufpos = 0;
416 *perform_io = WS_FALSE; 424 *perform_io = WS_FALSE;
562 } else if(ret > 0) { 570 } else if(ret > 0) {
563 st->max_read = chunklen; 571 st->max_read = chunklen;
564 st->read = 0; 572 st->read = 0;
565 st->remaining_len = chunkbuf_len - ret; 573 st->remaining_len = chunkbuf_len - ret;
566 if(st->remaining_len > 0) { 574 if(st->remaining_len > 0) {
567 memcpy(st->remaining_buf, st->chunk_buf, HTTP_STREAM_CBUF_SIZE); 575 //memcpy(st->remaining_buf, st->chunk_buf, HTTP_STREAM_CBUF_SIZE);
568 st->remaining_pos = st->chunk_buf_pos + ret; 576 *st->bufpos -= st->remaining_len;
577 //st->remaining_pos = ret;
569 } else { 578 } else {
570 st->remaining_pos = 0; 579 st->remaining_pos = 0;
571 } 580 }
572 st->remaining_len = chunkbuf_len - ret; 581 //st->remaining_len = chunkbuf_len - ret;
573 st->chunk_buf_pos = 0; 582 st->chunk_buf_pos = 0;
574 583
575 if(chunklen == 0) { 584 if(chunklen == 0) {
576 st->read_eof = WS_TRUE; 585 st->read_eof = WS_TRUE;
577 break; 586 break;

mercurial