Fix availableData bug

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22486 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-02-14 08:30:16 +00:00
parent 3503f70fa9
commit fe34b08b64
2 changed files with 41 additions and 4 deletions

View file

@ -1,3 +1,7 @@
2006-02-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSFileHandle.m: ([-availabledata]) fix error in last change
as we should block, but not for more than a single byte.
2006-02-13 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSCategories.m: Fix MD5 digest for 64bit CPU

View file

@ -1260,13 +1260,13 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
int len;
[self checkRead];
if (isNonBlocking == NO)
{
[self setNonBlocking: YES];
}
d = [NSMutableData dataWithCapacity: 0];
if (isStandardFile)
{
if (isNonBlocking == YES)
{
[self setNonBlocking: NO];
}
while ((len = [self read: buf length: sizeof(buf)]) > 0)
{
[d appendBytes: buf length: len];
@ -1274,7 +1274,40 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
}
else
{
if (isNonBlocking == NO)
{
[self setNonBlocking: YES];
}
len = [self read: buf length: sizeof(buf)];
if (len <= 0)
{
if (errno == EAGAIN || errno == EINTR)
{
/*
* Read would have blocked ... so try to get a single character
* in non-blocking mode (to ensure we wait until data arrives)
* and then try again.
* This ensures that we block for *some* data as we should.
*/
[self setNonBlocking: NO];
len = [self read: buf length: 1];
[self setNonBlocking: YES];
if (len == 1)
{
len = [self read: &buf[1] length: sizeof(buf) - 1];
if (len <= 0)
{
len = 1;
}
else
{
len = len + 1;
}
}
}
}
if (len > 0)
{
[d appendBytes: buf length: len];