mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Extension to support compression
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@11238 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e8cf6663c2
commit
15591bb852
8 changed files with 986 additions and 596 deletions
|
@ -1,3 +1,12 @@
|
|||
2001-10-24 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* configure.in: Check for zlib
|
||||
* Headers/gnustep/base/GSConfig.h.in: Define HAVE_ZLIB
|
||||
* Headers/gnustep/base/NSFileHandle.h: Add useCompression extension
|
||||
* Headers/gnustep/base/UnixFileHandle.h: ditto
|
||||
* Source/UnixFileHandle.m: Add support for read/write with compression
|
||||
using zlib. Activate with -useCompression
|
||||
|
||||
2001-10-19 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/Foundation/NSNumberFormatter.h: ivars aded and updated.
|
||||
|
|
|
@ -136,6 +136,11 @@ typedef @GS_ADDR@ gsaddr;
|
|||
#define GS_HAVE_I64 @GS_HAVE_I64@
|
||||
#define GS_HAVE_I128 @GS_HAVE_I128@
|
||||
|
||||
/*
|
||||
* Do we have zlib for file handle compression?
|
||||
*/
|
||||
#define HAVE_ZLIB @HAVE_ZLIB@
|
||||
|
||||
/*
|
||||
* Do we have the GNU Multiple-precision library for NSDecimal?
|
||||
*/
|
||||
|
|
|
@ -133,6 +133,7 @@ GS_EXPORT NSString* NSFileHandleOperationException;
|
|||
- (NSString*) socketAddress;
|
||||
- (NSString*) socketService;
|
||||
- (NSString*) socketProtocol;
|
||||
- (BOOL) useCompression;
|
||||
- (void) writeInBackgroundAndNotify: (NSData*)item forModes: (NSArray*)modes;
|
||||
- (void) writeInBackgroundAndNotify: (NSData*)item;
|
||||
- (BOOL) writeInProgress;
|
||||
|
|
|
@ -29,64 +29,76 @@
|
|||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
|
||||
#include <GSConfig.h>
|
||||
|
||||
#if HAVE_ZLIB
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
@interface UnixFileHandle : NSFileHandle <RunLoopEvents, GCFinalization>
|
||||
{
|
||||
int descriptor;
|
||||
BOOL closeOnDealloc;
|
||||
BOOL isStandardFile;
|
||||
BOOL isNullDevice;
|
||||
BOOL isNonBlocking;
|
||||
BOOL wasNonBlocking;
|
||||
BOOL acceptOK;
|
||||
BOOL connectOK;
|
||||
BOOL readOK;
|
||||
BOOL writeOK;
|
||||
NSMutableDictionary *readInfo;
|
||||
int readPos;
|
||||
NSMutableArray *writeInfo;
|
||||
int writePos;
|
||||
NSString *address;
|
||||
NSString *service;
|
||||
NSString *protocol;
|
||||
int descriptor;
|
||||
BOOL closeOnDealloc;
|
||||
BOOL isStandardFile;
|
||||
BOOL isNullDevice;
|
||||
BOOL isNonBlocking;
|
||||
BOOL wasNonBlocking;
|
||||
BOOL acceptOK;
|
||||
BOOL connectOK;
|
||||
BOOL readOK;
|
||||
BOOL writeOK;
|
||||
NSMutableDictionary *readInfo;
|
||||
int readPos;
|
||||
NSMutableArray *writeInfo;
|
||||
int writePos;
|
||||
NSString *address;
|
||||
NSString *service;
|
||||
NSString *protocol;
|
||||
#if HAVE_ZLIB
|
||||
gzFile gzDescriptor;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (id)initAsClientAtAddress:address
|
||||
service:service
|
||||
protocol:protocol;
|
||||
- (id)initAsClientInBackgroundAtAddress:address
|
||||
service:service
|
||||
protocol:protocol
|
||||
forModes:modes;
|
||||
- (id)initAsServerAtAddress:address
|
||||
service:service
|
||||
protocol:protocol;
|
||||
- (id)initForReadingAtPath:(NSString*)path;
|
||||
- (id)initForWritingAtPath:(NSString*)path;
|
||||
- (id)initForUpdatingAtPath:(NSString*)path;
|
||||
- (id)initWithStandardError;
|
||||
- (id)initWithStandardInput;
|
||||
- (id)initWithStandardOutput;
|
||||
- (id)initWithNullDevice;
|
||||
- (id) initAsClientAtAddress: (NSString*)address
|
||||
service: (NSString*)service
|
||||
protocol: (NSString*)protocol;
|
||||
- (id) initAsClientInBackgroundAtAddress: (NSString*)address
|
||||
service: (NSString*)service
|
||||
protocol: (NSString*)protocol
|
||||
forModes: (NSArray*)modes;
|
||||
- (id) initAsServerAtAddress: (NSString*)address
|
||||
service: (NSString*)service
|
||||
protocol: (NSString*)protocol;
|
||||
- (id) initForReadingAtPath: (NSString*)path;
|
||||
- (id) initForWritingAtPath: (NSString*)path;
|
||||
- (id) initForUpdatingAtPath: (NSString*)path;
|
||||
- (id) initWithStandardError;
|
||||
- (id) initWithStandardInput;
|
||||
- (id) initWithStandardOutput;
|
||||
- (id) initWithNullDevice;
|
||||
|
||||
- (void)checkAccept;
|
||||
- (void)checkConnect;
|
||||
- (void)checkRead;
|
||||
- (void)checkWrite;
|
||||
- (void) checkAccept;
|
||||
- (void) checkConnect;
|
||||
- (void) checkRead;
|
||||
- (void) checkWrite;
|
||||
|
||||
- (void)ignoreReadDescriptor;
|
||||
- (void)ignoreWriteDescriptor;
|
||||
- (void)setNonBlocking:(BOOL)flag;
|
||||
- (void)postReadNotification;
|
||||
- (void)postWriteNotification;
|
||||
- (void)receivedEvent: (void*)data
|
||||
type: (RunLoopEventType)type
|
||||
extra: (void*)extra
|
||||
forMode: (NSString*)mode;
|
||||
- (NSDate*)timedOutEvent: (void*)data
|
||||
- (void) ignoreReadDescriptor;
|
||||
- (void) ignoreWriteDescriptor;
|
||||
- (void) setNonBlocking: (BOOL)flag;
|
||||
- (void) postReadNotification;
|
||||
- (void) postWriteNotification;
|
||||
- (void) receivedEvent: (void*)data
|
||||
type: (RunLoopEventType)type
|
||||
extra: (void*)extra
|
||||
forMode: (NSString*)mode;
|
||||
- (NSDate*) timedOutEvent: (void*)data
|
||||
type: (RunLoopEventType)type
|
||||
forMode: (NSString*)mode;
|
||||
- (void)watchReadDescriptorForModes:(NSArray*)modes;
|
||||
- (void)watchWriteDescriptor;
|
||||
#ifndef NO_GNUSTEP
|
||||
- (BOOL) useCompression;
|
||||
#endif
|
||||
- (void) watchReadDescriptorForModes: (NSArray*)modes;
|
||||
- (void) watchWriteDescriptor;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -292,6 +292,9 @@
|
|||
/* Define if you have the <windows.h> header file. */
|
||||
#undef HAVE_WINDOWS_H
|
||||
|
||||
/* Define if you have the <zlib.h> header file. */
|
||||
#undef HAVE_ZLIB_H
|
||||
|
||||
/* Define if you have the giconv library (-lgiconv). */
|
||||
#undef HAVE_LIBGICONV
|
||||
|
||||
|
|
|
@ -215,6 +215,15 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
[self ignoreReadDescriptor];
|
||||
[self ignoreWriteDescriptor];
|
||||
|
||||
#if HAVE_ZLIB
|
||||
/*
|
||||
* The gzDescriptor should always be closed when we have done with it.
|
||||
*/
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
gzclose(gzDescriptor);
|
||||
}
|
||||
#endif
|
||||
if (descriptor != -1)
|
||||
{
|
||||
[self setNonBlocking: wasNonBlocking];
|
||||
|
@ -686,10 +695,22 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
|
||||
[self checkRead];
|
||||
if (isNonBlocking == YES)
|
||||
[self setNonBlocking: NO];
|
||||
{
|
||||
[self setNonBlocking: NO];
|
||||
}
|
||||
d = [NSMutableData dataWithCapacity: 0];
|
||||
if (isStandardFile)
|
||||
{
|
||||
#if HAVE_ZLIB
|
||||
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];
|
||||
|
@ -697,6 +718,16 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
}
|
||||
else
|
||||
{
|
||||
#if HAVE_ZLIB
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
if ((len = gzread(gzDescriptor, buf, sizeof(buf))) > 0)
|
||||
{
|
||||
[d appendBytes: buf length: len];
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if ((len = read(descriptor, buf, sizeof(buf))) > 0)
|
||||
{
|
||||
[d appendBytes: buf length: len];
|
||||
|
@ -721,6 +752,16 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
if (isNonBlocking == YES)
|
||||
[self setNonBlocking: NO];
|
||||
d = [NSMutableData dataWithCapacity: 0];
|
||||
#if HAVE_ZLIB
|
||||
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];
|
||||
|
@ -748,7 +789,15 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
|
||||
buf = NSZoneMalloc(NSDefaultMallocZone(), len);
|
||||
d = [NSMutableData dataWithBytesNoCopy: buf length: len];
|
||||
if ((got = read(descriptor, [d mutableBytes], len)) < 0)
|
||||
#if HAVE_ZLIB
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
got = gzread(gzDescriptor, [d mutableBytes], len);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
got = read(descriptor, [d mutableBytes], len);
|
||||
if (got < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
format: @"unable to read from descriptor - %s",
|
||||
|
@ -765,6 +814,13 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
{
|
||||
int chunk = len > sizeof(buf) ? sizeof(buf) : len;
|
||||
|
||||
#if HAVE_ZLIB
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
got = gzread(gzDescriptor, buf, chunk);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
got = read(descriptor, buf, chunk);
|
||||
if (got > 0)
|
||||
{
|
||||
|
@ -803,6 +859,13 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
{
|
||||
toWrite = NETBUF_SIZE;
|
||||
}
|
||||
#if HAVE_ZLIB
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
rval = gzwrite(gzDescriptor, (char*)ptr+pos, toWrite);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
rval = write(descriptor, (char*)ptr+pos, toWrite);
|
||||
if (rval < 0)
|
||||
{
|
||||
|
@ -905,7 +968,16 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
off_t result = -1;
|
||||
|
||||
if (isStandardFile && descriptor >= 0)
|
||||
result = lseek(descriptor, 0, SEEK_CUR);
|
||||
{
|
||||
#if HAVE_ZLIB
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
result = gzseek(gzDescriptor, 0, SEEK_CUR);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
result = lseek(descriptor, 0, SEEK_CUR);
|
||||
}
|
||||
if (result < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
|
@ -920,7 +992,16 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
off_t result = -1;
|
||||
|
||||
if (isStandardFile && descriptor >= 0)
|
||||
result = lseek(descriptor, 0, SEEK_END);
|
||||
{
|
||||
#if HAVE_ZLIB
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
result = gzseek(gzDescriptor, 0, SEEK_END);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
result = lseek(descriptor, 0, SEEK_END);
|
||||
}
|
||||
if (result < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
|
@ -935,7 +1016,16 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
off_t result = -1;
|
||||
|
||||
if (isStandardFile && descriptor >= 0)
|
||||
result = lseek(descriptor, (off_t)pos, SEEK_SET);
|
||||
{
|
||||
#if HAVE_ZLIB
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
result = gzseek(gzDescriptor, (off_t)pos, SEEK_SET);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
result = lseek(descriptor, (off_t)pos, SEEK_SET);
|
||||
}
|
||||
if (result < 0)
|
||||
{
|
||||
[NSException raise: NSFileHandleOperationException
|
||||
|
@ -957,6 +1047,13 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
[self ignoreWriteDescriptor];
|
||||
|
||||
[self setNonBlocking: wasNonBlocking];
|
||||
#if HAVE_ZLIB
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
gzclose(gzDescriptor);
|
||||
gzDescriptor = 0;
|
||||
}
|
||||
#endif
|
||||
(void)close(descriptor);
|
||||
descriptor = -1;
|
||||
acceptOK = NO;
|
||||
|
@ -1094,7 +1191,10 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
modes = nil;
|
||||
|
||||
if (readInfo)
|
||||
modes = (NSArray*)[readInfo objectForKey: NSFileHandleNotificationMonitorModes];
|
||||
{
|
||||
modes = (NSArray*)[readInfo objectForKey:
|
||||
NSFileHandleNotificationMonitorModes];
|
||||
}
|
||||
|
||||
if (modes && [modes count])
|
||||
{
|
||||
|
@ -1277,6 +1377,13 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
item = [readInfo objectForKey: NSFileHandleNotificationDataItem];
|
||||
length = [item length];
|
||||
|
||||
#if HAVE_ZLIB
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
received = gzread(gzDescriptor, buf, sizeof(buf));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
received = read(descriptor, buf, sizeof(buf));
|
||||
if (received == 0)
|
||||
{ // Read up to end of file.
|
||||
|
@ -1324,6 +1431,14 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
{
|
||||
int written;
|
||||
|
||||
#if HAVE_ZLIB
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
written = gzwrite(gzDescriptor, (char*)ptr+writePos,
|
||||
length-writePos);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
written = write(descriptor, (char*)ptr+writePos, length-writePos);
|
||||
if (written <= 0)
|
||||
{
|
||||
|
@ -1433,6 +1548,45 @@ getAddr(NSString* name, NSString* svc, NSString* pcl, struct sockaddr_in *sin)
|
|||
return service;
|
||||
}
|
||||
|
||||
- (BOOL) useCompression
|
||||
{
|
||||
#if HAVE_ZLIB
|
||||
int d;
|
||||
|
||||
if (gzDescriptor != 0)
|
||||
{
|
||||
return YES; // Already open
|
||||
}
|
||||
if (descriptor < 0)
|
||||
{
|
||||
return NO; // No descriptor available.
|
||||
}
|
||||
if (readOK == YES && writeOK == YES)
|
||||
{
|
||||
return NO; // Can't both read and write.
|
||||
}
|
||||
d = dup(descriptor);
|
||||
if (d < 0)
|
||||
{
|
||||
return NO; // No descriptor available.
|
||||
}
|
||||
if (readOK == YES)
|
||||
{
|
||||
gzDescriptor = gzdopen(d, "rb");
|
||||
}
|
||||
else
|
||||
{
|
||||
gzDescriptor = gzdopen(d, "wb");
|
||||
}
|
||||
if (gzDescriptor == 0)
|
||||
{
|
||||
close(d);
|
||||
return NO; // Open attempt failed.
|
||||
}
|
||||
return YES;
|
||||
#endif
|
||||
return NO;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
|
13
configure.in
13
configure.in
|
@ -552,9 +552,20 @@ AC_CHECK_FUNCS(shmctl)
|
|||
AC_CHECK_FUNCS(mmap)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# This function needed by UnixFileHandle.m
|
||||
# These used by UnixFileHandle.m
|
||||
#--------------------------------------------------------------------
|
||||
AC_CHECK_FUNCS(inet_aton)
|
||||
HAVE_ZLIB=0
|
||||
AC_CHECK_HEADERS(zlib.h)
|
||||
if test $ac_cv_header_zlib_h = yes; then
|
||||
AC_CHECK_LIB(z, gzopen, zlib_ok=yes, zlib_ok=no)
|
||||
if test "$zlib_ok" = yes; then
|
||||
base_libs="$LIBS"
|
||||
LIBS="$LIBS -lz"
|
||||
HAVE_ZLIB=1
|
||||
fi
|
||||
fi
|
||||
AC_SUBST(HAVE_ZLIB)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# These functions needed by NSTask.m
|
||||
|
|
Loading…
Reference in a new issue