/** * The scoop contains match data at scoop_next of length scoop_pos. This * function processes that match data, returning RS_DONE if it completes, * or RS_BLOCKED if it gets blocked. After it completes scoop_pos is reset * to still point at the next unscanned data. * * This function currently just removes data from the scoop and adjusts * scoop_pos appropriately. In the future this could be used for something * like context compressing of miss data. Note that it also calls * rs_tube_catchup to output any pending output. */ INLINE rs_result rs_processmatch(rs_job_t *job) { job->scoop_avail-=job->scoop_pos; job->scoop_next+=job->scoop_pos; job->scoop_pos=0; return rs_tube_catchup(job); }
static rs_result rs_delta_s_flush(rs_job_t *job) { rs_long_t match_pos; size_t match_len; rs_result result; rs_job_check(job); /* read the input into the scoop */ rs_getinput(job); /* output any pending output */ result=rs_tube_catchup(job); /* while output is not blocked and there is any remaining data */ while ((result==RS_DONE) && (job->scoop_pos < job->scoop_avail)) { /* check if this block matches */ if (rs_findmatch(job,&match_pos,&match_len)) { /* append the match and reset the weak_sum */ result=rs_appendmatch(job,match_pos,match_len); RollsumInit(&job->weak_sum); } else { /* rollout from weak_sum and append the miss byte */ RollsumRollout(&job->weak_sum,job->scoop_next[job->scoop_pos]); rs_trace("block reduced to %d", (int)job->weak_sum.count); result=rs_appendmiss(job,1); } } /* if we are not blocked, flush and set end statefn. */ if (result==RS_DONE) { result=rs_appendflush(job); job->statefn=rs_delta_s_end; } if (result==RS_DONE) { return RS_RUNNING; } return result; }
/** * \brief Get a block of data if possible, and see if it matches. * * On each call, we try to process all of the input data available on the * scoop and input buffer. */ static rs_result rs_delta_s_scan(rs_job_t *job) { rs_long_t match_pos; size_t match_len; rs_result result; Rollsum test; rs_job_check(job); /* read the input into the scoop */ rs_getinput(job); /* output any pending output from the tube */ result=rs_tube_catchup(job); /* while output is not blocked and there is a block of data */ while ((result==RS_DONE) && ((job->scoop_pos + job->block_len) < job->scoop_avail)) { /* check if this block matches */ if (rs_findmatch(job,&match_pos,&match_len)) { /* append the match and reset the weak_sum */ result=rs_appendmatch(job,match_pos,match_len); RollsumInit(&job->weak_sum); } else { /* rotate the weak_sum and append the miss byte */ RollsumRotate(&job->weak_sum,job->scoop_next[job->scoop_pos], job->scoop_next[job->scoop_pos+job->block_len]); result=rs_appendmiss(job,1); if (rs_roll_paranoia) { RollsumInit(&test); RollsumUpdate(&test,job->scoop_next+job->scoop_pos, job->block_len); if (RollsumDigest(&test) != RollsumDigest(&job->weak_sum)) { rs_fatal("mismatch between rolled sum %#x and check %#x", (int)RollsumDigest(&job->weak_sum), (int)RollsumDigest(&test)); } } } } /* if we completed OK */ if (result==RS_DONE) { /* if we reached eof, we can flush the last fragment */ if (job->stream->eof_in) { job->statefn=rs_delta_s_flush; return RS_RUNNING; } else { /* we are blocked waiting for more data */ return RS_BLOCKED; } } return result; }
static rs_result rs_job_work(rs_job_t *job, rs_buffers_t *buffers) { rs_result result; rs_job_check(job); if (!buffers) { rs_error("NULL buffer passed to rs_job_iter"); return RS_PARAM_ERROR; } job->stream = buffers; while (1) { result = rs_tube_catchup(job); if (result == RS_BLOCKED) return result; else if (result != RS_DONE) return rs_job_complete(job, result); if (job->statefn == rs_job_s_complete) { if (rs_tube_is_idle(job)) return RS_DONE; else return RS_BLOCKED; } else { result = job->statefn(job); if (result == RS_RUNNING) continue; else if (result == RS_BLOCKED) return result; else return rs_job_complete(job, result); } } /* TODO: Before returning, check that we actually made some * progress. If not, and we're not returning an error, this is a * bug. */ }
/** * The scoop contains miss data at scoop_next of length scoop_pos. This * function processes that miss data, returning RS_DONE if it completes, or * RS_BLOCKED if it gets blocked. After it completes scoop_pos is reset to * still point at the next unscanned data. * * This function uses rs_tube_copy to queue copying from the scoop into * output. and uses rs_tube_catchup to do the copying. This automaticly * removes data from the scoop, but this can block. While rs_tube_catchup * is blocked, scoop_pos does not point at legit data, so scanning can also * not proceed. * * In the future this could do compression of miss data before outputing * it. */ INLINE rs_result rs_processmiss(rs_job_t *job) { rs_tube_copy(job, job->scoop_pos); job->scoop_pos=0; return rs_tube_catchup(job); }