1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-15 01:04:37 +02:00

Make ioReadLine() read less aggressively.

ioReadLine() calls ioRead(), which aggressively tries to fill the output buffer, but this doesn't play well with blocking reads.

Give ioReadLine() an option that tells it to read only what is available.  That doesn't mean the function will never block but at least it won't do so by reading too far.
This commit is contained in:
David Steele
2018-11-12 21:18:53 -05:00
parent bc810e5a87
commit 086bc35ddc
3 changed files with 60 additions and 25 deletions

View File

@ -345,16 +345,26 @@ testRun(void)
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "DDD", " check buffer");
// Read line doesn't work without a linefeed
TEST_RESULT_STR(strPtr(ioReadLine(read)), NULL, "read line");
TEST_ERROR(ioReadLine(read), FileReadError, "unexpected eof while reading line");
// But those bytes can be picked up by a buffer read
bufUsedSet(buffer, 0);
TEST_RESULT_INT(ioRead(read, buffer), 3, "read buffer");
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "EFF", " check buffer");
buffer = bufNew(2);
TEST_RESULT_INT(ioRead(read, buffer), 2, "read buffer");
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "EF", " check buffer");
buffer = bufNew(1);
TEST_RESULT_INT(ioRead(read, buffer), 1, "read buffer");
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "F", " check buffer");
// Nothing left to read
TEST_RESULT_STR(strPtr(ioReadLine(read)), NULL, "read line");
TEST_ERROR(ioReadLine(read), FileReadError, "unexpected eof while reading line");
TEST_RESULT_INT(ioRead(read, buffer), 0, "read buffer");
// Error if buffer is full and there is no linefeed
ioBufferSizeSet(10);
read = ioBufferReadIo(ioBufferReadNew(bufNewZ("0123456789")));
ioReadOpen(read);
TEST_ERROR(ioReadLine(read), FileReadError, "unable to find line in 10 byte buffer");
}
// *****************************************************************************************************************************