2006-02-15 17:34:47 +00:00
|
|
|
/** Interface for NSStream for GNUStep
|
|
|
|
Copyright (C) 2006 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Derek Zhou <derekzhou@gmail.com>
|
|
|
|
Date: 2006
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2006-02-15 17:34:47 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2006-02-15 17:34:47 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2019-12-09 23:36:00 +00:00
|
|
|
Lesser General Public License for more details.
|
2006-02-15 17:34:47 +00:00
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2006-02-15 17:34:47 +00:00
|
|
|
License along with this library; if not, write to the Free
|
2024-11-07 13:37:59 +00:00
|
|
|
Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
|
2006-02-15 17:34:47 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __NSStream_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
#define __NSStream_h_GNUSTEP_BASE_INCLUDE
|
2006-10-31 07:05:46 +00:00
|
|
|
#import <GNUstepBase/GSVersionMacros.h>
|
2006-02-15 17:34:47 +00:00
|
|
|
|
2013-07-01 07:08:55 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4,GS_API_LATEST) && GS_API_VERSION( 10200,GS_API_LATEST)
|
2006-10-31 07:05:46 +00:00
|
|
|
|
|
|
|
#import <Foundation/NSObject.h>
|
2006-02-15 17:34:47 +00:00
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
enum {
|
2006-02-15 17:34:47 +00:00
|
|
|
NSStreamStatusNotOpen = 0,
|
|
|
|
NSStreamStatusOpening = 1,
|
|
|
|
NSStreamStatusOpen = 2,
|
|
|
|
NSStreamStatusReading = 3,
|
|
|
|
NSStreamStatusWriting = 4,
|
|
|
|
NSStreamStatusAtEnd = 5,
|
|
|
|
NSStreamStatusClosed = 6,
|
|
|
|
NSStreamStatusError = 7
|
2009-02-23 20:42:32 +00:00
|
|
|
};
|
|
|
|
typedef NSUInteger NSStreamStatus;
|
2006-02-15 17:34:47 +00:00
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
enum {
|
2006-02-15 17:34:47 +00:00
|
|
|
NSStreamEventNone = 0,
|
|
|
|
NSStreamEventOpenCompleted = 1,
|
|
|
|
NSStreamEventHasBytesAvailable = 2,
|
|
|
|
NSStreamEventHasSpaceAvailable = 4,
|
|
|
|
NSStreamEventErrorOccurred = 8,
|
|
|
|
NSStreamEventEndEncountered = 16
|
2009-02-23 20:42:32 +00:00
|
|
|
};
|
|
|
|
typedef NSUInteger NSStreamEvent;
|
2006-02-15 17:34:47 +00:00
|
|
|
|
|
|
|
@class NSError;
|
|
|
|
@class NSHost;
|
|
|
|
@class NSInputStream;
|
|
|
|
@class NSOutputStream;
|
|
|
|
@class NSString;
|
2006-02-16 00:05:51 +00:00
|
|
|
@class NSRunLoop;
|
2017-04-04 07:44:00 +00:00
|
|
|
@class NSURL;
|
2006-02-15 17:34:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* NSStream is an abstract class for objects representing streams.
|
|
|
|
*/
|
2021-01-18 13:20:14 +00:00
|
|
|
GS_EXPORT_CLASS
|
2006-02-15 17:34:47 +00:00
|
|
|
@interface NSStream : NSObject
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns by reference an NSInputStream object and NSOutputStream
|
|
|
|
* object for a socket connection with the specified port on host.
|
|
|
|
*/
|
|
|
|
+ (void) getStreamsToHost: (NSHost *)host
|
2009-02-23 20:42:32 +00:00
|
|
|
port: (NSInteger)port
|
2006-02-15 17:34:47 +00:00
|
|
|
inputStream: (NSInputStream **)inputStream
|
|
|
|
outputStream: (NSOutputStream **)outputStream;
|
|
|
|
|
|
|
|
/**
|
2006-08-11 13:27:10 +00:00
|
|
|
* Closes the receiver.<br />
|
|
|
|
* Repeated calls to this method on the same stream are quietly ignored.
|
2006-02-15 17:34:47 +00:00
|
|
|
*/
|
|
|
|
- (void) close;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the receiver's delegate.
|
|
|
|
*/
|
|
|
|
- (id) delegate;
|
|
|
|
|
|
|
|
/**
|
2006-08-11 13:27:10 +00:00
|
|
|
* Opens the receiving stream.<br />
|
|
|
|
* Upon completion of the open operation, an NSStreamEventOpenCompleted
|
|
|
|
* event is sent to the recevier's delegate.<br />
|
|
|
|
* Repeated calls to this method on the same stream are quietly ignored.
|
2006-02-15 17:34:47 +00:00
|
|
|
*/
|
|
|
|
- (void) open;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the receiver's property for the specified key.
|
|
|
|
*/
|
|
|
|
- (id) propertyForKey: (NSString *)key;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the receiver from the NSRunLoop specified by aRunLoop
|
2006-08-11 13:27:10 +00:00
|
|
|
* running in the mode.<br />
|
|
|
|
* Attempts to remove the receiver from a run loop or a mode in
|
|
|
|
* which it has not been scheduled are quietly ignored.
|
2006-02-15 17:34:47 +00:00
|
|
|
*/
|
|
|
|
- (void) removeFromRunLoop: (NSRunLoop *)aRunLoop forMode: (NSString *)mode;
|
|
|
|
|
|
|
|
/**
|
2006-08-11 13:27:10 +00:00
|
|
|
* Schedules the receiver on aRunLoop using the specified mode.<br />
|
|
|
|
* You must not attempt to add a stream to more than one run loop,
|
|
|
|
* but you may call this method multiple times to add the receiver
|
|
|
|
* in different modes for the same run loop.
|
2006-02-15 17:34:47 +00:00
|
|
|
*/
|
|
|
|
- (void) scheduleInRunLoop: (NSRunLoop *)aRunLoop forMode: (NSString *)mode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the receiver's delegate.
|
|
|
|
*/
|
|
|
|
- (void) setDelegate: (id)delegate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the value of the property specified by key to property, returns YES
|
|
|
|
* if the key-value pair are accepted by the receiver.
|
|
|
|
*/
|
|
|
|
- (BOOL) setProperty: (id)property forKey: (NSString *)key;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an NSError object representing the stream error, or nil if no error
|
|
|
|
* has been encountered.
|
|
|
|
*/
|
|
|
|
- (NSError *) streamError;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the receiver's status.
|
|
|
|
*/
|
|
|
|
- (NSStreamStatus) streamStatus;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@class NSData;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NSInputStream is a subclass of NSStream that provides read-only
|
|
|
|
* stream functionality.
|
|
|
|
*/
|
2021-03-22 14:28:38 +00:00
|
|
|
GS_EXPORT_CLASS
|
2006-02-15 17:34:47 +00:00
|
|
|
@interface NSInputStream : NSStream
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns an initialized NSInputStream object
|
|
|
|
* for reading from data.
|
|
|
|
*/
|
|
|
|
+ (id) inputStreamWithData: (NSData *)data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns an initialized NSInputStream object that reads data from
|
|
|
|
* the file at the specified path.
|
|
|
|
*/
|
|
|
|
+ (id) inputStreamWithFileAtPath: (NSString *)path;
|
|
|
|
|
2017-03-27 09:44:13 +00:00
|
|
|
/**
|
|
|
|
* Creates and returns an initialized NSInputStream object that reads data from
|
|
|
|
* the specified URL.
|
|
|
|
*/
|
|
|
|
+ (id) inputStreamWithURL: (NSURL *)url;
|
|
|
|
|
2006-02-15 17:34:47 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the read buffer in buffer and, by reference, the number
|
|
|
|
* of bytes available in len.
|
|
|
|
*/
|
2009-02-23 20:42:32 +00:00
|
|
|
- (BOOL) getBuffer: (uint8_t **)buffer length: (NSUInteger *)len;
|
2006-02-15 17:34:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns YES if the receiver has bytes available to read.
|
|
|
|
* The receiver may also return YES if a read must be attempted
|
|
|
|
* in order to determine the availability of bytes.
|
|
|
|
*/
|
|
|
|
- (BOOL) hasBytesAvailable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an initialized NSInputStream object for reading from data.
|
|
|
|
*/
|
|
|
|
- (id) initWithData: (NSData *)data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an initialized NSInputStream object for reading from the file at the
|
|
|
|
* specified path.
|
|
|
|
*/
|
|
|
|
- (id) initWithFileAtPath: (NSString *)path;
|
|
|
|
|
2017-03-27 09:44:13 +00:00
|
|
|
/**
|
|
|
|
* Returns an initialized NSInputStream object for reading from the
|
|
|
|
* specified URL.
|
|
|
|
*/
|
|
|
|
- (id) initWithURL: (NSURL *)url;
|
|
|
|
|
2006-02-15 17:34:47 +00:00
|
|
|
/**
|
|
|
|
* Reads up to len bytes into buffer, returning the actual number of bytes read.
|
|
|
|
*/
|
2009-02-23 20:42:32 +00:00
|
|
|
- (NSInteger) read: (uint8_t *)buffer maxLength: (NSUInteger)len;
|
2006-02-15 17:34:47 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NSOutputStream is a subclass of NSStream that provides
|
|
|
|
* write-only stream functionality.
|
|
|
|
*/
|
2021-03-22 14:28:38 +00:00
|
|
|
GS_EXPORT_CLASS
|
2006-02-15 17:34:47 +00:00
|
|
|
@interface NSOutputStream : NSStream
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns an initialized NSOutputStream object
|
|
|
|
* that can write to buffer, up to a maximum of capacity bytes.
|
|
|
|
*/
|
2009-02-23 20:42:32 +00:00
|
|
|
+ (id) outputStreamToBuffer: (uint8_t *)buffer capacity: (NSUInteger)capacity;
|
2006-02-15 17:34:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns an initialized NSOutputStream object
|
|
|
|
* for writing to the file specified by path.
|
|
|
|
*/
|
|
|
|
+ (id) outputStreamToFileAtPath: (NSString *)path append: (BOOL)shouldAppend;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates and returns an initialized NSOutputStream object
|
|
|
|
* that will write stream data to memory.
|
|
|
|
*/
|
|
|
|
+ (id) outputStreamToMemory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns YES if the receiver can be written to,
|
|
|
|
* or if a write must be attempted
|
|
|
|
* in order to determine if space is available.
|
|
|
|
*/
|
|
|
|
- (BOOL) hasSpaceAvailable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an initialized NSOutputStream object that can write to buffer,
|
|
|
|
* up to a maximum of capacity bytes.
|
|
|
|
*/
|
2009-02-23 20:42:32 +00:00
|
|
|
- (id) initToBuffer: (uint8_t *)buffer capacity: (NSUInteger)capacity;
|
2006-02-15 17:34:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an initialized NSOutputStream object for writing to the file
|
|
|
|
* specified by path.<br />
|
|
|
|
* If shouldAppend is YES, newly written data will be appended to any
|
|
|
|
* existing file contents.
|
|
|
|
*/
|
|
|
|
- (id) initToFileAtPath: (NSString *)path append: (BOOL)shouldAppend;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an initialized NSOutputStream object that will write to memory.
|
|
|
|
*/
|
|
|
|
- (id) initToMemory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Writes the contents of buffer, up to a maximum of len bytes,
|
|
|
|
* to the receiver.
|
|
|
|
*/
|
2009-02-23 20:42:32 +00:00
|
|
|
- (NSInteger) write: (const uint8_t *)buffer maxLength: (NSUInteger)len;
|
2006-02-15 17:34:47 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2006-02-16 19:19:30 +00:00
|
|
|
|
2006-02-15 17:34:47 +00:00
|
|
|
GS_EXPORT NSString * const NSStreamDataWrittenToMemoryStreamKey;
|
|
|
|
GS_EXPORT NSString * const NSStreamFileCurrentOffsetKey;
|
|
|
|
|
|
|
|
GS_EXPORT NSString * const NSStreamSocketSecurityLevelKey;
|
|
|
|
GS_EXPORT NSString * const NSStreamSocketSecurityLevelNone;
|
|
|
|
GS_EXPORT NSString * const NSStreamSocketSecurityLevelSSLv2;
|
|
|
|
GS_EXPORT NSString * const NSStreamSocketSecurityLevelSSLv3;
|
|
|
|
GS_EXPORT NSString * const NSStreamSocketSecurityLevelTLSv1;
|
|
|
|
GS_EXPORT NSString * const NSStreamSocketSecurityLevelNegotiatedSSL;
|
|
|
|
GS_EXPORT NSString * const NSStreamSocketSSLErrorDomain;
|
|
|
|
GS_EXPORT NSString * const NSStreamSOCKSErrorDomain;
|
|
|
|
GS_EXPORT NSString * const NSStreamSOCKSProxyConfigurationKey;
|
|
|
|
GS_EXPORT NSString * const NSStreamSOCKSProxyHostKey;
|
|
|
|
GS_EXPORT NSString * const NSStreamSOCKSProxyPasswordKey;
|
|
|
|
GS_EXPORT NSString * const NSStreamSOCKSProxyPortKey;
|
|
|
|
GS_EXPORT NSString * const NSStreamSOCKSProxyUserKey;
|
|
|
|
GS_EXPORT NSString * const NSStreamSOCKSProxyVersion4;
|
|
|
|
GS_EXPORT NSString * const NSStreamSOCKSProxyVersion5;
|
|
|
|
GS_EXPORT NSString * const NSStreamSOCKSProxyVersionKey;
|
|
|
|
|
2013-12-30 13:37:40 +00:00
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7,GS_API_LATEST) && GS_PROTOCOLS_HAVE_OPTIONAL
|
2013-12-20 10:01:16 +00:00
|
|
|
@protocol NSStreamDelegate <NSObject>
|
|
|
|
@optional
|
2014-02-02 08:44:18 +00:00
|
|
|
- (void) stream: (NSStream*)sStream handleEvent: (NSStreamEvent)anEvent;
|
|
|
|
@end
|
2013-12-20 10:01:16 +00:00
|
|
|
#else
|
2006-08-08 17:05:55 +00:00
|
|
|
/**
|
|
|
|
* Informal protocol for delegates of instance of the [NSStream] class.
|
|
|
|
*/
|
|
|
|
@interface NSObject (NSStreamDelegate)
|
|
|
|
- (void) stream: (NSStream*)sStream handleEvent: (NSStreamEvent)anEvent;
|
|
|
|
@end
|
2014-02-02 08:44:18 +00:00
|
|
|
#endif
|
2006-02-15 17:34:47 +00:00
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-05 12:41:40 +00:00
|
|
|
#if !NO_GNUSTEP && !defined(GNUSTEP_BASE_INTERNAL)
|
|
|
|
#import <GNUstepBase/NSStream+GNUstepBase.h>
|
|
|
|
#endif
|
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#endif /* 100200 */
|
|
|
|
|
|
|
|
#endif /* __NSStream_h_GNUSTEP_BASE_INCLUDE */
|