mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
Improved IO->bufferRead to always return requested number of bytes until EOF.
This commit is contained in:
parent
e951c4f9c2
commit
4e9f8da9a6
@ -143,6 +143,10 @@
|
||||
|
||||
<p>Abstracted code to determine which database cluster is the master and which are standbys.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Improved <code>IO->bufferRead</code> to always return requested number of bytes until EOF.</p>
|
||||
</release-item>
|
||||
</release-refactor-list>
|
||||
</release-core-list>
|
||||
|
||||
|
@ -370,7 +370,6 @@ sub bufferRead
|
||||
# Set working variables
|
||||
my $iRemainingSize = $iRequestSize;
|
||||
$iOffset = defined($iOffset) ? $iOffset : 0;
|
||||
$bBlock = defined($bBlock) ? $bBlock : false;
|
||||
|
||||
# If there is data left over in the buffer from lineRead then use it
|
||||
if (defined($self->{strBuffer}) && $self->{iBufferPos} < $self->{iBufferSize})
|
||||
@ -390,21 +389,20 @@ sub bufferRead
|
||||
$iRemainingSize -= $iReadSize;
|
||||
undef($self->{strBuffer});
|
||||
|
||||
return $iReadSize if !$bBlock || $iRemainingSize == 0;
|
||||
return $iReadSize if $iRemainingSize == 0;
|
||||
|
||||
$iOffset += $iReadSize;
|
||||
}
|
||||
}
|
||||
|
||||
# If this is a blocking read then loop until all bytes have been read - else error.
|
||||
# If this is a blocking read then loop until all bytes have been read, else error. If not blocking read until the request size
|
||||
# has been met or EOF.
|
||||
#
|
||||
# This link (http://docstore.mik.ua/orelly/perl/cookbook/ch07_15.htm) demonstrates a way to implement this same loop without
|
||||
# using select. Not sure if it would be better but the link has been left here so it can be found in the future if the
|
||||
# implementation needs to be changed.
|
||||
if ($bBlock)
|
||||
{
|
||||
my $fTimeStart = gettimeofday();
|
||||
my $fRemaining = $self->{iProtocolTimeout};
|
||||
my $fRemaining = 1; #$self->{iProtocolTimeout};
|
||||
|
||||
do
|
||||
{
|
||||
@ -426,7 +424,16 @@ sub bufferRead
|
||||
# Check for EOF
|
||||
if ($iReadSize == 0)
|
||||
{
|
||||
confess &log(ERROR, 'unexpected EOF', ERROR_FILE_READ);
|
||||
if (defined($bBlock) && $bBlock)
|
||||
{
|
||||
confess &log(ERROR,
|
||||
'EOF after ' . ($iRequestSize - $iRemainingSize) . " bytes but expected ${iRequestSize}",
|
||||
ERROR_FILE_READ);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $iRequestSize - $iRemainingSize;
|
||||
}
|
||||
}
|
||||
|
||||
# Update remaining size and return when it reaches 0
|
||||
@ -450,22 +457,6 @@ sub bufferRead
|
||||
confess &log(ERROR, "unable to read ${iRequestSize} bytes after $self->{iProtocolTimeout} seconds", ERROR_PROTOCOL_TIMEOUT);
|
||||
}
|
||||
|
||||
# Otherwise do a non-blocking read and return whatever bytes are ready
|
||||
my $iReadSize = sysread($self->{hIn}, $$tBufferRef, $iRemainingSize, $iOffset);
|
||||
|
||||
# Process errors from sysread
|
||||
if (!defined($iReadSize))
|
||||
{
|
||||
my $strError = $!;
|
||||
|
||||
$self->waitPid();
|
||||
confess &log(ERROR, 'unable to read' . (defined($strError) ? ": ${strError}" : ''));
|
||||
}
|
||||
|
||||
# Return the number of bytes read
|
||||
return $iReadSize;
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# bufferWrite
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user