mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
Add ioWriteFlush() to flush pending output.
By default the IoWrite object does not write until the output buffer is full but this is a problem for protocol messages that must be sent in order to get a response. ioWriteFlush() is not called internally by IoWrite but can be used at any time to immediately write all bytes from the output buffer without closing the IoWrite object.
This commit is contained in:
parent
7918629f59
commit
480e1da798
@ -70,6 +70,10 @@
|
||||
<p>Make <code>ioReadLine()</code> read less aggressively.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Add <code>ioWriteFlush()</code> to flush pending output.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Add <id>base</id> variants to all integer to string conversion functions.</p>
|
||||
</release-item>
|
||||
|
@ -145,6 +145,30 @@ ioWriteLine(IoWrite *this, const String *string)
|
||||
FUNCTION_DEBUG_RESULT_VOID();
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Flush any data in the output buffer
|
||||
|
||||
This does not end writing and if there are filters that are not done it might not have the intended effect.
|
||||
***********************************************************************************************************************************/
|
||||
void
|
||||
ioWriteFlush(IoWrite *this)
|
||||
{
|
||||
FUNCTION_DEBUG_BEGIN(logLevelTrace);
|
||||
FUNCTION_DEBUG_PARAM(IO_WRITE, this);
|
||||
|
||||
FUNCTION_TEST_ASSERT(this != NULL);
|
||||
FUNCTION_TEST_ASSERT(this->opened && !this->closed);
|
||||
FUNCTION_DEBUG_END();
|
||||
|
||||
if (bufUsed(this->output) > 0)
|
||||
{
|
||||
this->interface.write(this->driver, this->output);
|
||||
bufUsedZero(this->output);
|
||||
}
|
||||
|
||||
FUNCTION_DEBUG_RESULT_VOID();
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Close the IO and write any additional data that has not been written yet
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -22,6 +22,7 @@ Functions
|
||||
void ioWriteOpen(IoWrite *this);
|
||||
void ioWrite(IoWrite *this, const Buffer *buffer);
|
||||
void ioWriteLine(IoWrite *this, const String *string);
|
||||
void ioWriteFlush(IoWrite *this);
|
||||
void ioWriteClose(IoWrite *this);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -414,16 +414,23 @@ testRun(void)
|
||||
TEST_RESULT_VOID(ioWrite(ioBufferWriteIo(bufferWrite), NULL), " write 0 bytes");
|
||||
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "AABB\n\n", " check write");
|
||||
|
||||
TEST_RESULT_VOID(ioWrite(ioBufferWriteIo(bufferWrite), bufNewStr(strNew("Z"))), " write string");
|
||||
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "AABB\n\n", " no change because output buffer is not full");
|
||||
TEST_RESULT_VOID(ioWriteFlush(ioBufferWriteIo(bufferWrite)), " flush output");
|
||||
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "AABB\n\nZZ", " check output is flushed");
|
||||
TEST_RESULT_VOID(ioWriteFlush(ioBufferWriteIo(bufferWrite)), " flush again (nothing to flush)");
|
||||
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "AABB\n\nZZ", " check output is unchanged");
|
||||
|
||||
TEST_RESULT_VOID(ioWrite(ioBufferWriteIo(bufferWrite), bufNewZ("12345")), " write 4 bytes");
|
||||
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "AABB\n\n112233445", " check write");
|
||||
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "AABB\n\nZZ112233445", " check write");
|
||||
|
||||
TEST_RESULT_VOID(ioWriteClose(ioBufferWriteIo(bufferWrite)), " close buffer write object");
|
||||
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "AABB\n\n1122334455XXX", " check write after close");
|
||||
TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "AABB\n\nZZ1122334455XXX", " check write after close");
|
||||
|
||||
TEST_RESULT_PTR(ioWriteFilterGroup(ioBufferWriteIo(bufferWrite)), filterGroup, " check filter group");
|
||||
TEST_RESULT_UINT(
|
||||
varUInt64(ioFilterGroupResult(filterGroup, ioFilterType(ioSizeFilter(sizeFilter)))), 8, " check filter result");
|
||||
TEST_RESULT_UINT(varUInt64(ioFilterGroupResult(filterGroup, strNew("size2"))), 19, " check filter result");
|
||||
varUInt64(ioFilterGroupResult(filterGroup, ioFilterType(ioSizeFilter(sizeFilter)))), 9, " check filter result");
|
||||
TEST_RESULT_UINT(varUInt64(ioFilterGroupResult(filterGroup, strNew("size2"))), 21, " check filter result");
|
||||
|
||||
TEST_RESULT_VOID(ioBufferWriteFree(bufferWrite), " free buffer write object");
|
||||
TEST_RESULT_VOID(ioBufferWriteFree(NULL), " free NULL buffer write object");
|
||||
|
Loading…
Reference in New Issue
Block a user