summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDonovan Baarda <abo@minkirri.apana.org.au>2020-06-02 14:22:58 +1000
committerDonovan Baarda <abo@minkirri.apana.org.au>2020-06-02 14:22:58 +1000
commit476cab5ee806f094defff552fe8d027e79672f49 (patch)
tree3fd7468e2d4eee3cc43b19bac68c0e8194bcf82b /src
parent36d0f285e90ba1ad47261e169d82c4f4519ca0fe (diff)
downloadlibrsync-476cab5ee806f094defff552fe8d027e79672f49.tar.gz
Use size_t consistently for buffer sizes and tidy stream related code.
In job.h change copy_len and write_len to size_t from rs_long_t and int. In stream.[hc] and tube.c remove unimplemented/unused rs_buffers_is_empty(), rs_check_tube(), and rs_buffers_check_exit(). Change all len arguments to size_t. Change rs_tube_catchup() return to rs_result from int. Tidy code order in header to reflect order in code. Make trace output more consistent.
Diffstat (limited to 'src')
-rw-r--r--src/job.h5
-rw-r--r--src/stream.c24
-rw-r--r--src/stream.h24
-rw-r--r--src/tube.c29
4 files changed, 30 insertions, 52 deletions
diff --git a/src/job.h b/src/job.h
index 2663e14..061c4b4 100644
--- a/src/job.h
+++ b/src/job.h
@@ -82,11 +82,11 @@ struct rs_job {
/** If USED is >0, then buf contains that much write data to be sent out. */
rs_byte_t write_buf[36];
- int write_len;
+ size_t write_len;
/** If \p copy_len is >0, then that much data should be copied through
* from the input. */
- rs_long_t copy_len;
+ size_t copy_len;
/** Copy from the basis position. */
rs_long_t basis_pos, basis_len;
@@ -94,7 +94,6 @@ struct rs_job {
/** Callback used to copy data from the basis into the output. */
rs_copy_cb *copy_cb;
void *copy_arg;
-
};
rs_job_t *rs_job_new(const char *, rs_result (*statefn)(rs_job_t *));
diff --git a/src/stream.c b/src/stream.c
index 8ce4177..78e60fb 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -93,45 +93,27 @@
* This always does the copy immediately. Most functions should call
* rs_tube_copy() to cause the copy to happen gradually as space becomes
* available. */
-int rs_buffers_copy(rs_buffers_t *stream, int max_len)
+size_t rs_buffers_copy(rs_buffers_t *stream, size_t len)
{
- int len = max_len;
-
assert(len > 0);
- if ((unsigned)len > stream->avail_in) {
+ if (len > stream->avail_in) {
rs_trace("copy limited to " FMT_SIZE " available input bytes",
stream->avail_in);
len = stream->avail_in;
}
-
- if ((unsigned)len > stream->avail_out) {
+ if (len > stream->avail_out) {
rs_trace("copy limited to " FMT_SIZE " available output bytes",
stream->avail_out);
len = stream->avail_out;
}
-
if (!len)
return 0;
/* rs_trace("stream copied chunk of %d bytes", len); */
-
memcpy(stream->next_out, stream->next_in, len);
-
stream->next_out += len;
stream->avail_out -= len;
-
stream->next_in += len;
stream->avail_in -= len;
-
return len;
}
-
-/** Assert input is empty or output is full.
- *
- * Whenever a stream processing function exits, it should have done so because
- * it has either consumed all the input or has filled the output buffer. This
- * function checks that simple postcondition. */
-void rs_buffers_check_exit(rs_buffers_t const *stream)
-{
- assert(stream->avail_in == 0 || stream->avail_out == 0);
-}
diff --git a/src/stream.h b/src/stream.h
index b52ac48..ada70b8 100644
--- a/src/stream.h
+++ b/src/stream.h
@@ -27,20 +27,16 @@
| And sons who died on the Burma Railway.
*/
-int rs_buffers_is_empty(rs_buffers_t *stream);
-int rs_buffers_copy(rs_buffers_t *stream, int len);
+size_t rs_buffers_copy(rs_buffers_t *stream, size_t len);
-int rs_tube_catchup(rs_job_t *);
-void rs_tube_write(rs_job_t *, void const *buf, size_t len);
-void rs_tube_copy(rs_job_t *, int len);
-int rs_tube_is_idle(rs_job_t const *);
-void rs_check_tube(rs_job_t *);
+rs_result rs_tube_catchup(rs_job_t *job);
+int rs_tube_is_idle(rs_job_t const *job);
+void rs_tube_write(rs_job_t *job, void const *buf, size_t len);
+void rs_tube_copy(rs_job_t *job, size_t len);
-void rs_buffers_check_exit(rs_buffers_t const *);
-
-void rs_scoop_advance(rs_job_t *, size_t len);
-rs_result rs_scoop_readahead(rs_job_t *, size_t len, void **ptr);
-rs_result rs_scoop_read(rs_job_t *, size_t len, void **ptr);
-rs_result rs_scoop_read_rest(rs_job_t *, size_t *len, void **ptr);
-size_t rs_scoop_total_avail(rs_job_t *job);
void rs_scoop_input(rs_job_t *job, size_t len);
+void rs_scoop_advance(rs_job_t *job, size_t len);
+rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr);
+rs_result rs_scoop_read(rs_job_t *job, size_t len, void **ptr);
+rs_result rs_scoop_read_rest(rs_job_t *job, size_t *len, void **ptr);
+size_t rs_scoop_total_avail(rs_job_t *job);
diff --git a/src/tube.c b/src/tube.c
index 842b3ba..4983e31 100644
--- a/src/tube.c
+++ b/src/tube.c
@@ -63,10 +63,10 @@
static void rs_tube_catchup_write(rs_job_t *job)
{
rs_buffers_t *stream = job->stream;
- int len = job->write_len;
+ size_t len = job->write_len;
assert(len > 0);
- if ((size_t)len > stream->avail_out)
+ if (len > stream->avail_out)
len = stream->avail_out;
if (!stream->avail_out) {
rs_trace("no output space available");
@@ -80,7 +80,8 @@ static void rs_tube_catchup_write(rs_job_t *job)
/* Still something left in the tube, shuffle it to the front. */
memmove(job->write_buf, job->write_buf + len, job->write_len);
}
- rs_trace("wrote %d bytes from tube, %d remaining", len, job->write_len);
+ rs_trace("wrote " FMT_SIZE " bytes from tube, " FMT_SIZE " remaining", len,
+ job->write_len);
}
/** Execute a copy command, taking data from the scoop.
@@ -102,9 +103,9 @@ static void rs_tube_copy_from_scoop(rs_job_t *job)
job->scoop_avail -= len;
job->scoop_next += len;
job->copy_len -= len;
- rs_trace("caught up on " FMT_SIZE " copied bytes from scoop, " FMT_SIZE
- " remain there, " FMT_LONG " remain to be copied", len,
- job->scoop_avail, job->copy_len);
+ rs_trace("copied " FMT_SIZE " bytes from scoop, " FMT_SIZE
+ " left in scoop, " FMT_SIZE " left to copy", len, job->scoop_avail,
+ job->copy_len);
}
/** Catch up on an outstanding copy command.
@@ -122,10 +123,11 @@ static void rs_tube_catchup_copy(rs_job_t *job)
}
/* If there's more to copy and we emptied the scoop, send input. */
if (job->copy_len && !job->scoop_avail) {
- size_t this_copy = rs_buffers_copy(job->stream, job->copy_len);
- job->copy_len -= this_copy;
- rs_trace("copied " FMT_SIZE " bytes from input buffer, " FMT_LONG
- " remain to be copied", this_copy, job->copy_len);
+ size_t len = rs_buffers_copy(job->stream, job->copy_len);
+ job->copy_len -= len;
+ rs_trace("copied " FMT_SIZE " bytes from stream, " FMT_SIZE
+ "left in stream, " FMT_SIZE " left to copy", len,
+ job->stream->avail_in, job->copy_len);
}
}
@@ -133,7 +135,7 @@ static void rs_tube_catchup_copy(rs_job_t *job)
*
* \return RS_DONE if the tube is now empty and ready to accept another
* command, RS_BLOCKED if there is still stuff waiting to go out. */
-int rs_tube_catchup(rs_job_t *job)
+rs_result rs_tube_catchup(rs_job_t *job)
{
if (job->write_len) {
rs_tube_catchup_write(job);
@@ -146,8 +148,7 @@ int rs_tube_catchup(rs_job_t *job)
if (job->copy_len) {
if (job->stream->eof_in && !job->stream->avail_in
&& !job->scoop_avail) {
- rs_error
- ("reached end of file while copying literal data through buffers");
+ rs_error("reached end of file while copying data");
return RS_INPUT_ENDED;
}
return RS_BLOCKED;
@@ -175,7 +176,7 @@ int rs_tube_is_idle(rs_job_t const *job)
* \todo Try to do the copy immediately, and return a result. Then, people can
* try to continue if possible. Is this really required? Callers can just go
* out and back in again after flushing the tube. */
-void rs_tube_copy(rs_job_t *job, int len)
+void rs_tube_copy(rs_job_t *job, size_t len)
{
assert(job->copy_len == 0);