mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Tidyup
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14601 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6ab3117782
commit
53a37c7e08
2 changed files with 52 additions and 98 deletions
|
@ -88,6 +88,7 @@
|
||||||
- (void) setNonBlocking: (BOOL)flag;
|
- (void) setNonBlocking: (BOOL)flag;
|
||||||
- (void) postReadNotification;
|
- (void) postReadNotification;
|
||||||
- (void) postWriteNotification;
|
- (void) postWriteNotification;
|
||||||
|
- (int) read: (void*)buf length: (int)len;
|
||||||
- (void) receivedEvent: (void*)data
|
- (void) receivedEvent: (void*)data
|
||||||
type: (RunLoopEventType)type
|
type: (RunLoopEventType)type
|
||||||
extra: (void*)extra
|
extra: (void*)extra
|
||||||
|
@ -99,6 +100,7 @@
|
||||||
- (BOOL) useCompression;
|
- (BOOL) useCompression;
|
||||||
- (void) watchReadDescriptorForModes: (NSArray*)modes;
|
- (void) watchReadDescriptorForModes: (NSArray*)modes;
|
||||||
- (void) watchWriteDescriptor;
|
- (void) watchWriteDescriptor;
|
||||||
|
- (int) write: (const void*)buf length: (int)len;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,46 @@ static NSString* NotificationKey = @"NSFileHandleNotificationKey";
|
||||||
|
|
||||||
@implementation GSFileHandle
|
@implementation GSFileHandle
|
||||||
|
|
||||||
|
- (int) read: (void*)buf length: (int)len
|
||||||
|
{
|
||||||
|
#if USE_ZLIB
|
||||||
|
if (gzDescriptor != 0)
|
||||||
|
{
|
||||||
|
len = gzread(gzDescriptor, buf, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if (isSocket)
|
||||||
|
{
|
||||||
|
len = recv(descriptor, buf, len, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = read(descriptor, buf, len);
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int) write: (const void*)buf length: (int)len
|
||||||
|
{
|
||||||
|
#if USE_ZLIB
|
||||||
|
if (gzDescriptor != 0)
|
||||||
|
{
|
||||||
|
len = gzwrite(gzDescriptor, (char*)buf, len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if (isSocket)
|
||||||
|
{
|
||||||
|
len = send(descriptor, buf, len, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = write(descriptor, buf, len);
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
||||||
{
|
{
|
||||||
|
@ -1242,41 +1282,14 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
d = [NSMutableData dataWithCapacity: 0];
|
d = [NSMutableData dataWithCapacity: 0];
|
||||||
if (isStandardFile)
|
if (isStandardFile)
|
||||||
{
|
{
|
||||||
#if USE_ZLIB
|
while ((len = [self read: buf length: sizeof(buf)]) > 0)
|
||||||
if (gzDescriptor != 0)
|
|
||||||
{
|
|
||||||
while ((len = gzread(gzDescriptor, buf, sizeof(buf))) > 0)
|
|
||||||
{
|
|
||||||
[d appendBytes: buf length: len];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
while ((len = read(descriptor, buf, sizeof(buf))) > 0)
|
|
||||||
{
|
{
|
||||||
[d appendBytes: buf length: len];
|
[d appendBytes: buf length: len];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if USE_ZLIB
|
len = [self read: buf length: sizeof(buf)];
|
||||||
if (gzDescriptor != 0)
|
|
||||||
{
|
|
||||||
if ((len = gzread(gzDescriptor, buf, sizeof(buf))) > 0)
|
|
||||||
{
|
|
||||||
[d appendBytes: buf length: len];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
if (isSocket)
|
|
||||||
{
|
|
||||||
len = recv(descriptor, buf, sizeof(buf), 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
len = read(descriptor, buf, sizeof(buf));
|
|
||||||
}
|
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
[d appendBytes: buf length: len];
|
[d appendBytes: buf length: len];
|
||||||
|
@ -1303,17 +1316,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
[self setNonBlocking: NO];
|
[self setNonBlocking: NO];
|
||||||
}
|
}
|
||||||
d = [NSMutableData dataWithCapacity: 0];
|
d = [NSMutableData dataWithCapacity: 0];
|
||||||
#if USE_ZLIB
|
while ((len = [self read: buf length: sizeof(buf)]) > 0)
|
||||||
if (gzDescriptor != 0)
|
|
||||||
{
|
|
||||||
while ((len = gzread(gzDescriptor, buf, sizeof(buf))) > 0)
|
|
||||||
{
|
|
||||||
[d appendBytes: buf length: len];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
while ((len = read(descriptor, buf, sizeof(buf))) > 0)
|
|
||||||
{
|
{
|
||||||
[d appendBytes: buf length: len];
|
[d appendBytes: buf length: len];
|
||||||
}
|
}
|
||||||
|
@ -1342,14 +1345,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
|
|
||||||
buf = NSZoneMalloc(NSDefaultMallocZone(), len);
|
buf = NSZoneMalloc(NSDefaultMallocZone(), len);
|
||||||
d = [NSMutableData dataWithBytesNoCopy: buf length: len];
|
d = [NSMutableData dataWithBytesNoCopy: buf length: len];
|
||||||
#if USE_ZLIB
|
got = [self read: [d mutableBytes] length: len];
|
||||||
if (gzDescriptor != 0)
|
|
||||||
{
|
|
||||||
got = gzread(gzDescriptor, [d mutableBytes], len);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
got = read(descriptor, [d mutableBytes], len);
|
|
||||||
if (got < 0)
|
if (got < 0)
|
||||||
{
|
{
|
||||||
[NSException raise: NSFileHandleOperationException
|
[NSException raise: NSFileHandleOperationException
|
||||||
|
@ -1367,14 +1363,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
{
|
{
|
||||||
int chunk = len > sizeof(buf) ? sizeof(buf) : len;
|
int chunk = len > sizeof(buf) ? sizeof(buf) : len;
|
||||||
|
|
||||||
#if USE_ZLIB
|
got = [self read: buf length: chunk];
|
||||||
if (gzDescriptor != 0)
|
|
||||||
{
|
|
||||||
got = gzread(gzDescriptor, buf, chunk);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
got = read(descriptor, buf, chunk);
|
|
||||||
if (got > 0)
|
if (got > 0)
|
||||||
{
|
{
|
||||||
[d appendBytes: buf length: got];
|
[d appendBytes: buf length: got];
|
||||||
|
@ -1412,14 +1401,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
{
|
{
|
||||||
toWrite = NETBUF_SIZE;
|
toWrite = NETBUF_SIZE;
|
||||||
}
|
}
|
||||||
#if USE_ZLIB
|
rval = [self write: (char*)ptr+pos length: toWrite];
|
||||||
if (gzDescriptor != 0)
|
|
||||||
{
|
|
||||||
rval = gzwrite(gzDescriptor, (char*)ptr+pos, toWrite);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
rval = write(descriptor, (char*)ptr+pos, toWrite);
|
|
||||||
if (rval < 0)
|
if (rval < 0)
|
||||||
{
|
{
|
||||||
if (errno == EAGAIN || errno == EINTR)
|
if (errno == EAGAIN || errno == EINTR)
|
||||||
|
@ -1972,7 +1954,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
int size = sizeof(sin);
|
int size = sizeof(sin);
|
||||||
|
|
||||||
h = [[GSFileHandle alloc] initWithFileDescriptor: desc
|
h = [[[self class] alloc] initWithFileDescriptor: desc
|
||||||
closeOnDealloc: YES];
|
closeOnDealloc: YES];
|
||||||
h->isSocket = YES;
|
h->isSocket = YES;
|
||||||
getpeername(desc, (struct sockaddr*)&sin, &size);
|
getpeername(desc, (struct sockaddr*)&sin, &size);
|
||||||
|
@ -2011,21 +1993,7 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
length = sizeof(buf);
|
length = sizeof(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USE_ZLIB
|
received = [self read: buf length: length];
|
||||||
if (gzDescriptor != 0)
|
|
||||||
{
|
|
||||||
received = gzread(gzDescriptor, buf, length);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
if (isSocket)
|
|
||||||
{
|
|
||||||
received = recv(descriptor, buf, length, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
received = read(descriptor, buf, length);
|
|
||||||
}
|
|
||||||
if (received == 0)
|
if (received == 0)
|
||||||
{ // Read up to end of file.
|
{ // Read up to end of file.
|
||||||
[self postReadNotification];
|
[self postReadNotification];
|
||||||
|
@ -2095,24 +2063,8 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr";
|
||||||
{
|
{
|
||||||
int written;
|
int written;
|
||||||
|
|
||||||
#if USE_ZLIB
|
written = [self write: (char*)ptr+writePos
|
||||||
if (gzDescriptor != 0)
|
length: length-writePos];
|
||||||
{
|
|
||||||
written = gzwrite(gzDescriptor, (char*)ptr+writePos,
|
|
||||||
length-writePos);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
if (isSocket)
|
|
||||||
{
|
|
||||||
written = send(descriptor, (char*)ptr+writePos,
|
|
||||||
length-writePos, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
written = write(descriptor, (char*)ptr+writePos,
|
|
||||||
length-writePos);
|
|
||||||
}
|
|
||||||
if (written <= 0)
|
if (written <= 0)
|
||||||
{
|
{
|
||||||
if (written < 0 && errno != EAGAIN && errno != EINTR)
|
if (written < 0 && errno != EAGAIN && errno != EINTR)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue