/** * Called after reading a command byte to pull in its parameters and * then setup to execute the command. */ static rs_result rs_patch_s_params(rs_job_t *job) { rs_result result; int len = job->cmd->len_1 + job->cmd->len_2; void *p; assert(len); result = rs_scoop_readahead(job, len, &p); if (result != RS_DONE) return result; /* we now must have LEN bytes buffered */ result = rs_suck_netint(job, &job->param1, job->cmd->len_1); /* shouldn't fail, since we already checked */ assert(result == RS_DONE); if (job->cmd->len_2) { result = rs_suck_netint(job, &job->param2, job->cmd->len_2); assert(result == RS_DONE); } job->statefn = rs_patch_s_run; return RS_RUNNING; }
/** Read LEN bytes if possible, and remove them from the input scoop. * * \param *job An rs_job_t pointer to the job instance. * * \param len The length of the data in the ptr buffer. * * \param **ptr will be updated to point to a read-only buffer holding the * data, if enough is available. * * \return RS_DONE if there was enough data, RS_BLOCKED if there was not enough * data yet, or RS_INPUT_ENDED if there was not enough data and at EOF. */ rs_result rs_scoop_read(rs_job_t *job, size_t len, void **ptr) { rs_result result; result = rs_scoop_readahead(job, len, ptr); if (result == RS_DONE) rs_scoop_advance(job, len); return result; }