aboutsummaryrefslogtreecommitdiffstats
path: root/common/iobuf.h
diff options
context:
space:
mode:
authorNeal H. Walfield <[email protected]>2015-09-02 08:24:33 +0000
committerNeal H. Walfield <[email protected]>2015-09-02 08:24:49 +0000
commitf2d75ac7dc58f5ea59b231be6b83fea939b43ab8 (patch)
treefa92a8ca32657961549140557d2c40f76e02523e /common/iobuf.h
parentiobuf: Rename IOBUF_TEMP to IOBUF_OUTPUT_TEMP. (diff)
downloadgnupg-f2d75ac7dc58f5ea59b231be6b83fea939b43ab8.tar.gz
gnupg-f2d75ac7dc58f5ea59b231be6b83fea939b43ab8.zip
iobuf: Add the IOBUF_INPUT_TEMP type to improve input temp handling.
* common/iobuf.h (enum iobuf_use): Add new member, IOBUF_INPUT_TEMP. * common/iobuf.c (iobuf_temp_with_content): Create the iobuf as an IOBUF_INPUT_TEMP, not an IOBUF_INPUT buffer. Assert that LENGTH == A->D.SIZE. (iobuf_push_filter2): If A is an IOBUF_INPUT_TEMP, then make the new filter an IOBUF_INPUT filter and set its buffer size to IOBUF_BUFFER_SIZE. (underflow): If A is an IOBUF_INPUT_TEMP, then just return EOF; don't remove already read data. (iobuf_seek): If A is an IOBUF_INPUT_TEMP, don't discard the buffered data. (iobuf_alloc): Allow USE == IOBUF_INPUT_TEMP. (pop_filter): Allow USE == IOBUF_INPUT_TEMP. (iobuf_peek): Allow USE == IOBUF_INPUT_TEMP. (iobuf_writebyte): Fail if USE == IOBUF_INPUT_TEMP. (iobuf_write): Fail if USE == IOBUF_INPUT_TEMP. (iobuf_writestr): Fail if USE == IOBUF_INPUT_TEMP. (iobuf_flush_temp): Fail if USE == IOBUF_INPUT_TEMP. -- Signed-off-by: Neal H. Walfield <[email protected]>. Introduce a new iobuf type, IOBUF_INPUT_TEMP. Use this for the iobuf created by iobuf_temp_with_content instead of IOBUF_INPUT. This was necessary so that seeking and peeking correctly work on this type of iobuf. In particular, seeking didn't work because we discarded the buffered data and peeking didn't work because we discarded data which was already read, which made seeking later impossible.
Diffstat (limited to 'common/iobuf.h')
-rw-r--r--common/iobuf.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/common/iobuf.h b/common/iobuf.h
index b65ea60d7..bce6c3162 100644
--- a/common/iobuf.h
+++ b/common/iobuf.h
@@ -124,12 +124,15 @@ enum iobuf_use
/* Pipeline is in input mode. The data flows from the end to the
beginning. That is, when reading from the pipeline, the first
filter gets its input from the second filter, etc. */
- IOBUF_INPUT=1,
+ IOBUF_INPUT,
+ /* Pipeline is in input mode. The last filter in the pipeline is
+ a temporary buffer from which the data is "read". */
+ IOBUF_INPUT_TEMP,
/* Pipeline is in output mode. The data flows from the beginning
to the end. That is, when writing to the pipeline, the user
writes to the first filter, which transforms the data and sends
it to the second filter, etc. */
- IOBUF_OUTPUT=2,
+ IOBUF_OUTPUT,
/* Pipeline is in output mode. The last filter in the pipeline is
a temporary buffer that grows as necessary. */
IOBUF_OUTPUT_TEMP
@@ -274,7 +277,8 @@ int iobuf_is_pipe_filename (const char *fname);
create a new primary source or primary sink, i.e., the last filter
in the pipeline.
- USE is IOBUF_INPUT, IOBUF_OUTPUT or IOBUF_OUTPUT_TEMP.
+ USE is IOBUF_INPUT, IOBUF_INPUT_TEMP, IOBUF_OUTPUT or
+ IOBUF_OUTPUT_TEMP.
BUFSIZE is the desired internal buffer size (that is, the size of
the typical read / write request). */