mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fix bug causing short reads of data
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25016 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d918d7535f
commit
d512da4a7f
2 changed files with 19 additions and 31 deletions
|
@ -1,3 +1,8 @@
|
|||
2007-04-13 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSFileHandle.m: ([-readDataOfLength:]) fix bug which could
|
||||
cause short reads.
|
||||
|
||||
2007-04-12 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Tool/HTMLLinker.m: Re-add.
|
||||
|
|
|
@ -1353,51 +1353,34 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
|||
{
|
||||
NSMutableData *d;
|
||||
int got;
|
||||
char buf[READ_SIZE];
|
||||
|
||||
[self checkRead];
|
||||
if (isNonBlocking == YES)
|
||||
{
|
||||
[self setNonBlocking: NO];
|
||||
}
|
||||
if (len <= 65536)
|
||||
{
|
||||
char *buf;
|
||||
|
||||
buf = NSZoneMalloc(NSDefaultMallocZone(), len);
|
||||
d = [NSMutableData dataWithBytesNoCopy: buf length: len];
|
||||
got = [self read: [d mutableBytes] length: len];
|
||||
if (got < 0)
|
||||
d = [NSMutableData dataWithCapacity: len < READ_SIZE ? len : READ_SIZE];
|
||||
do
|
||||
{
|
||||
int chunk = len > sizeof(buf) ? sizeof(buf) : len;
|
||||
|
||||
got = [self read: buf length: chunk];
|
||||
if (got > 0)
|
||||
{
|
||||
[d appendBytes: buf length: got];
|
||||
len -= got;
|
||||
}
|
||||
else if (got < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"unable to read from descriptor - %@",
|
||||
[NSError _last]];
|
||||
}
|
||||
[d setLength: got];
|
||||
}
|
||||
else
|
||||
{
|
||||
char buf[READ_SIZE];
|
||||
while (len > 0 && got > 0);
|
||||
|
||||
d = [NSMutableData dataWithCapacity: 0];
|
||||
do
|
||||
{
|
||||
int chunk = len > sizeof(buf) ? sizeof(buf) : len;
|
||||
|
||||
got = [self read: buf length: chunk];
|
||||
if (got > 0)
|
||||
{
|
||||
[d appendBytes: buf length: got];
|
||||
len -= got;
|
||||
}
|
||||
else if (got < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"unable to read from descriptor - %@",
|
||||
[NSError _last]];
|
||||
}
|
||||
}
|
||||
while (len > 0 && got > 0);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue