diff --git a/ChangeLog b/ChangeLog index 33efeb893..31ce4ee96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2002-06-23 Richard Frith-Macdonald + + * Headers/Foundation/NSFileHandle.h: add async read of specific length. + * Source/NSFileHandle.m: Make the async wconvenience methods call + the core ones. + * Source/UnixFileHandle.m: Remove async convenience methods and add + one to read specified length of data. + 2002-06-21 Richard Frith-Macdonald * Source/GSMime.m: add a few consistency checks to raise an exception diff --git a/Headers/gnustep/base/NSFileHandle.h b/Headers/gnustep/base/NSFileHandle.h index 0f2ef2bb8..f10d7455c 100644 --- a/Headers/gnustep/base/NSFileHandle.h +++ b/Headers/gnustep/base/NSFileHandle.h @@ -62,14 +62,14 @@ // Asynchronous I/O operations -- (void) acceptConnectionInBackgroundAndNotifyForModes: (NSArray*)modes; - (void) acceptConnectionInBackgroundAndNotify; -- (void) readInBackgroundAndNotifyForModes: (NSArray*)modes; +- (void) acceptConnectionInBackgroundAndNotifyForModes: (NSArray*)modes; - (void) readInBackgroundAndNotify; -- (void) readToEndOfFileInBackgroundAndNotifyForModes: (NSArray*)modes; +- (void) readInBackgroundAndNotifyForModes: (NSArray*)modes; - (void) readToEndOfFileInBackgroundAndNotify; -- (void) waitForDataInBackgroundAndNotifyForModes: (NSArray*)modes; +- (void) readToEndOfFileInBackgroundAndNotifyForModes: (NSArray*)modes; - (void) waitForDataInBackgroundAndNotify; +- (void) waitForDataInBackgroundAndNotifyForModes: (NSArray*)modes; // Seeking within a file @@ -132,6 +132,9 @@ GS_EXPORT NSString * const NSFileHandleOperationException; service: (NSString*)service protocol: (NSString*)protocol forModes: (NSArray*)modes; +- (void) readDataInBackgroundAndNotifyLength: (unsigned)len; +- (void) readDataInBackgroundAndNotifyLength: (unsigned)len + forModes: (NSArray*)modes; - (BOOL) readInProgress; - (NSString*) socketAddress; - (NSString*) socketService; diff --git a/Source/NSFileHandle.m b/Source/NSFileHandle.m index 26903814e..fd5cc922c 100644 --- a/Source/NSFileHandle.m +++ b/Source/NSFileHandle.m @@ -198,42 +198,62 @@ static Class NSFileHandle_ssl_class = nil; // Asynchronous I/O operations +- (void) acceptConnectionInBackgroundAndNotify +{ + [self acceptConnectionInBackgroundAndNotifyForModes: nil]; +} + - (void) acceptConnectionInBackgroundAndNotifyForModes: (NSArray*)modes { [self subclassResponsibility: _cmd]; } -- (void) acceptConnectionInBackgroundAndNotify +/** + * Call -readInBackgroundAndNotifyForModes: with nil modes. + */ +- (void) readInBackgroundAndNotify { - [self subclassResponsibility: _cmd]; + [self readInBackgroundAndNotifyForModes: nil]; } +/** + * Set up an asynchonous read operation which will cause a notification to + * be sent when any amount of data (or end of file) is read. + */ - (void) readInBackgroundAndNotifyForModes: (NSArray*)modes { [self subclassResponsibility: _cmd]; } -- (void) readInBackgroundAndNotify +/** + * Call -readToEndOfFileInBackgroundAndNotifyForModes: with nil modes. + */ +- (void) readToEndOfFileInBackgroundAndNotify { - [self subclassResponsibility: _cmd]; + [self readToEndOfFileInBackgroundAndNotifyForModes: nil]; } +/** + * Set up an asynchonous read operation which will cause a notification to + * be sent when end of file is read. + */ - (void) readToEndOfFileInBackgroundAndNotifyForModes: (NSArray*)modes { [self subclassResponsibility: _cmd]; } -- (void) readToEndOfFileInBackgroundAndNotify -{ - [self subclassResponsibility: _cmd]; -} - -- (void) waitForDataInBackgroundAndNotifyForModes: (NSArray*)modes -{ - [self subclassResponsibility: _cmd]; -} - +/** + * Call -waitForDataInBackgroundAndNotifyForModes: with nil modes. + */ - (void) waitForDataInBackgroundAndNotify +{ + [self waitForDataInBackgroundAndNotifyForModes: nil]; +} + +/** + * Set up to provide a notification when data can be read from the handle. + */ +- (void) waitForDataInBackgroundAndNotifyForModes: (NSArray*)modes { [self subclassResponsibility: _cmd]; } @@ -404,6 +424,24 @@ NSString * const NSFileHandleOperationException protocol: protocol]); } +/** + * Call -readDataInBackgroundAndNotifyLength:forModes: with nil modes. + */ +- (void) readDataInBackgroundAndNotifyLength: (unsigned)len +{ + [self readDataInBackgroundAndNotifyLength: len forModes: nil]; +} + +/** + * Set up an asynchonous read operation which will cause a notification to + * be sent when the specified amount of data (or end of file) is read. + */ +- (void) readDataInBackgroundAndNotifyLength: (unsigned)len + forModes: (NSArray*)modes +{ + [self subclassResponsibility: _cmd]; +} + - (BOOL) readInProgress { [self subclassResponsibility: _cmd]; @@ -430,12 +468,18 @@ NSString * const NSFileHandleOperationException return NO; } -- (void) writeInBackgroundAndNotify: (NSData*)item forModes: (NSArray*)modes +/** + * Call -writeInBackgroundAndNotify:forModes: with nil modes. + */ +- (void) writeInBackgroundAndNotify: (NSData*)item { - [self subclassResponsibility: _cmd]; + [self writeInBackgroundAndNotify: item forModes: nil]; } -- (void) writeInBackgroundAndNotify: (NSData*)item +/** + * Write the specified data asynchronously, and notify on completion. + */ +- (void) writeInBackgroundAndNotify: (NSData*)item forModes: (NSArray*)modes { [self subclassResponsibility: _cmd]; } diff --git a/Source/UnixFileHandle.m b/Source/UnixFileHandle.m index 0b6164d4a..24bf189d4 100644 --- a/Source/UnixFileHandle.m +++ b/Source/UnixFileHandle.m @@ -1384,9 +1384,26 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; [self watchReadDescriptorForModes: modes]; } -- (void) acceptConnectionInBackgroundAndNotify +- (void) readDataInBackgroundAndNotifyLength: (unsigned)len + forModes: (NSArray*)modes { - [self acceptConnectionInBackgroundAndNotifyForModes: nil]; + NSMutableData *d; + + [self checkRead]; + if (len > 0x7fffffff) + { + [NSException raise: NSInvalidArgumentException + format: @"length (%u) too large", len]; + } + readMax = len; + RELEASE(readInfo); + readInfo = [[NSMutableDictionary alloc] initWithCapacity: 4]; + [readInfo setObject: NSFileHandleReadCompletionNotification + forKey: NotificationKey]; + d = [[NSMutableData alloc] initWithCapacity: readMax]; + [readInfo setObject: d forKey: NSFileHandleNotificationDataItem]; + RELEASE(d); + [self watchReadDescriptorForModes: modes]; } - (void) readInBackgroundAndNotifyForModes: (NSArray*)modes @@ -1405,11 +1422,6 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; [self watchReadDescriptorForModes: modes]; } -- (void) readInBackgroundAndNotify -{ - return [self readInBackgroundAndNotifyForModes: nil]; -} - - (void) readToEndOfFileInBackgroundAndNotifyForModes: (NSArray*)modes { NSMutableData *d; @@ -1426,11 +1438,6 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; [self watchReadDescriptorForModes: modes]; } -- (void) readToEndOfFileInBackgroundAndNotify -{ - return [self readToEndOfFileInBackgroundAndNotifyForModes: nil]; -} - - (void) waitForDataInBackgroundAndNotifyForModes: (NSArray*)modes { [self checkRead]; @@ -1444,11 +1451,6 @@ NSString * const GSSOCKSRecvAddr = @"GSSOCKSRecvAddr"; [self watchReadDescriptorForModes: modes]; } -- (void) waitForDataInBackgroundAndNotify -{ - return [self waitForDataInBackgroundAndNotifyForModes: nil]; -} - // Seeking within a file - (unsigned long long) offsetInFile