/** Read from scoop without advancing. * * Ask for LEN bytes of input from the stream. If that much data is available, * then return a pointer to it in PTR, advance the stream input pointer over * the data, and return RS_DONE. If there's not enough data, then accept * whatever is there into a buffer, advance over it, and return RS_BLOCKED. * * The data is not actually removed from the input, so this function lets you * do readahead. If you want to keep any of the data, you should also call * rs_scoop_advance() to skip over it. */ rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr) { rs_buffers_t *stream = job->stream; rs_job_check(job); if (!job->scoop_avail && stream->avail_in >= len) { /* The scoop is empty and there's enough data in the input. */ *ptr = stream->next_in; rs_trace("got " FMT_SIZE " bytes direct from input", len); return RS_DONE; } else if (job->scoop_avail < len && stream->avail_in) { /* There is not enough data in the scoop. */ rs_trace("scoop has less than " FMT_SIZE " bytes, scooping from " FMT_SIZE " input bytes", len, stream->avail_in); rs_scoop_input(job, len); } if (job->scoop_avail >= len) { /* There is enough data in the scoop now. */ rs_trace("scoop has at least " FMT_SIZE " bytes, this is enough", job->scoop_avail); *ptr = job->scoop_next; return RS_DONE; } else if (stream->eof_in) { /* Not enough input data and at EOF. */ rs_trace("reached end of input stream"); return RS_INPUT_ENDED; } else { /* Not enough input data yet. */ rs_trace("blocked with insufficient input data"); return RS_BLOCKED; } }
void rs_getinput(rs_job_t *job) { size_t len; len=rs_scoop_total_avail(job); if (job->scoop_avail < len) { rs_scoop_input(job,len); } }