void rq_found_data(struct request *rq,struct chunk *c) { struct chunk *d; struct ranges r; struct rangei ri; int64_t x,y; while(c) { log_debug(("processing report of data at %"PRId64"+%"PRId64, c->offset,c->length)); /* Help satisfy request */ ranges_init(&r); ranges_add(&r,c->offset,c->offset+c->length); ranges_remove(&r,0,rq->offset); ranges_remove(&r,rq->offset+rq->length,INT64_MAX); ranges_start(&r,&ri); while(ranges_next(&ri,&x,&y)) { log_debug(("copying range %"PRId64"-%"PRId64,x,y)); memcpy(rq->out+x-rq->offset,c->out+x-c->offset,y-x); } ranges_free(&r); ranges_remove(&(rq->desired),c->offset,c->offset+c->length); /* Update desire given knoledge of eof */ if(c->eof) { log_debug(("early eof: rest of file does not exist")); ranges_remove(&(rq->desired),c->offset+c->length,INT64_MAX); } /* Move chunks to request (for later write) */ src_acquire(c->origin); d = c->next; c->next = rq->chunks; rq->chunks = c; c = d; } }
int combinatorics_test(FILE *stream_in, FILE *stream_out, pc_options_t const *options) { ranges_t *ranges = ranges_alloc(options->channels); if ( ranges == NULL ) { return(PC_ERROR_MEM); } ranges_init(ranges); ranges_set_stops(ranges, options->channels); while ( ranges_next(ranges) == PC_SUCCESS ) { ranges_fprintf(stream_out, ranges); } ranges_free(&ranges); return(PC_SUCCESS); }