IOS NSStream.h

来源:互联网 发布:花衣吹笛手 知乎 编辑:程序博客网 时间:2024/06/08 03:46



/*NSStream.h        Copyright (c) 2003-2014, Apple Inc. All rights reserved*/#import <Foundation/NSObject.h>@class NSData, NSDictionary, NSError, NSHost, NSInputStream, NSOutputStream, NSRunLoop, NSString, NSURL;@protocol NSStreamDelegate;typedef NS_ENUM(NSUInteger, NSStreamStatus) {    NSStreamStatusNotOpen = 0,    NSStreamStatusOpening = 1,    NSStreamStatusOpen = 2,    NSStreamStatusReading = 3,    NSStreamStatusWriting = 4,    NSStreamStatusAtEnd = 5,    NSStreamStatusClosed = 6,    NSStreamStatusError = 7};typedef NS_OPTIONS(NSUInteger, NSStreamEvent) {    NSStreamEventNone = 0,    NSStreamEventOpenCompleted = 1UL << 0,    NSStreamEventHasBytesAvailable = 1UL << 1,    NSStreamEventHasSpaceAvailable = 1UL << 2,    NSStreamEventErrorOccurred = 1UL << 3,    NSStreamEventEndEncountered = 1UL << 4};// NSStream is an abstract class encapsulating the common API to NSInputStream and NSOutputStream.// Subclassers of NSInputStream and NSOutputStream must also implement these methods.@interface NSStream : NSObject- (void)open;- (void)close;@property (assign) id <NSStreamDelegate> delegate;    // By default, a stream is its own delegate, and subclassers of NSInputStream and NSOutputStream must maintain this contract. [someStream setDelegate:nil] must restore this behavior. As usual, delegates are not retained.- (id)propertyForKey:(NSString *)key;- (BOOL)setProperty:(id)property forKey:(NSString *)key;- (void)scheduleInRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;- (void)removeFromRunLoop:(NSRunLoop *)aRunLoop forMode:(NSString *)mode;@property (readonly) NSStreamStatus streamStatus;@property (readonly, copy) NSError *streamError;@end// NSInputStream is an abstract class representing the base functionality of a read stream.// Subclassers are required to implement these methods.@interface NSInputStream : NSStream- (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len;    // reads up to length bytes into the supplied buffer, which must be at least of size len. Returns the actual number of bytes read.- (BOOL)getBuffer:(uint8_t **)buffer length:(NSUInteger *)len;    // returns in O(1) a pointer to the buffer in 'buffer' and by reference in 'len' how many bytes are available. This buffer is only valid until the next stream operation. Subclassers may return NO for this if it is not appropriate for the stream type. This may return NO if the buffer is not available.@property (readonly) BOOL hasBytesAvailable;    // returns YES if the stream has bytes available or if it impossible to tell without actually doing the read.- (instancetype)initWithData:(NSData *)data NS_DESIGNATED_INITIALIZER;- (instancetype)initWithURL:(NSURL *)url NS_AVAILABLE(10_6, 4_0) NS_DESIGNATED_INITIALIZER;@end// NSOutputStream is an abstract class representing the base functionality of a write stream.// Subclassers are required to implement these methods.@interface NSOutputStream : NSStream- (NSInteger)write:(const uint8_t *)buffer maxLength:(NSUInteger)len;    // writes the bytes from the specified buffer to the stream up to len bytes. Returns the number of bytes actually written.@property (readonly) BOOL hasSpaceAvailable;    // returns YES if the stream can be written to or if it is impossible to tell without actually doing the write.- (instancetype)initToMemory NS_DESIGNATED_INITIALIZER;- (instancetype)initToBuffer:(uint8_t *)buffer capacity:(NSUInteger)capacity NS_DESIGNATED_INITIALIZER;- (instancetype)initWithURL:(NSURL *)url append:(BOOL)shouldAppend NS_AVAILABLE(10_6, 4_0) NS_DESIGNATED_INITIALIZER;@end@interface NSStream (NSSocketStreamCreationExtensions)+ (void)getStreamsToHostWithName:(NSString *)hostname port:(NSInteger)port inputStream:(NSInputStream **)inputStream outputStream:(NSOutputStream **)outputStream NS_AVAILABLE(10_10, 8_0);#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))+ (void)getStreamsToHost:(NSHost *)host port:(NSInteger)port inputStream:(NSInputStream **)inputStream outputStream:(NSOutputStream **)outputStream NS_DEPRECATED_MAC(10_3, 10_10, "Please use getStreamsToHostWithName:port:inputStream:outputStream: instead”");#endif@end@interface NSStream (NSStreamBoundPairCreationExtensions)+ (void)getBoundStreamsWithBufferSize:(NSUInteger)bufferSize inputStream:(NSInputStream **)inputStream outputStream:(NSOutputStream **)outputStream NS_AVAILABLE(10_10, 8_0);@end// The NSInputStreamExtensions category contains additional initializers and convenience routines for dealing with NSInputStreams.@interface NSInputStream (NSInputStreamExtensions)- (instancetype)initWithFileAtPath:(NSString *)path;+ (instancetype)inputStreamWithData:(NSData *)data;+ (instancetype)inputStreamWithFileAtPath:(NSString *)path;+ (instancetype)inputStreamWithURL:(NSURL *)url NS_AVAILABLE(10_6, 4_0);@end// The NSOutputStreamExtensions category contains additional initializers and convenience routines for dealing with NSOutputStreams.@interface NSOutputStream (NSOutputStreamExtensions)- (instancetype)initToFileAtPath:(NSString *)path append:(BOOL)shouldAppend;+ (instancetype)outputStreamToMemory;+ (instancetype)outputStreamToBuffer:(uint8_t *)buffer capacity:(NSUInteger)capacity;+ (instancetype)outputStreamToFileAtPath:(NSString *)path append:(BOOL)shouldAppend;+ (instancetype)outputStreamWithURL:(NSURL *)url append:(BOOL)shouldAppend NS_AVAILABLE(10_6, 4_0);@end<span style="color:#ff0000;">@protocol NSStreamDelegate <NSObject>@optional- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode;</span>@end// NSString constants for the propertyForKey/setProperty:forKey: API// String constants for the setting of the socket security level.FOUNDATION_EXPORT NSString * const NSStreamSocketSecurityLevelKeyNS_AVAILABLE(10_3, 2_0);// use this as the key for setting one of the following values for the security level of the target stream.FOUNDATION_EXPORT NSString * const NSStreamSocketSecurityLevelNoneNS_AVAILABLE(10_3, 2_0);FOUNDATION_EXPORT NSString * const NSStreamSocketSecurityLevelSSLv2NS_AVAILABLE(10_3, 2_0);FOUNDATION_EXPORT NSString * const NSStreamSocketSecurityLevelSSLv3NS_AVAILABLE(10_3, 2_0);FOUNDATION_EXPORT NSString * const NSStreamSocketSecurityLevelTLSv1NS_AVAILABLE(10_3, 2_0);FOUNDATION_EXPORT NSString * const NSStreamSocketSecurityLevelNegotiatedSSLNS_AVAILABLE(10_3, 2_0);FOUNDATION_EXPORT NSString * const NSStreamSOCKSProxyConfigurationKeyNS_AVAILABLE(10_3, 2_0);// Value is an NSDictionary containing the key/value pairs below. The dictionary returned from SystemConfiguration for SOCKS proxies will work without alteration.FOUNDATION_EXPORT NSString * const NSStreamSOCKSProxyHostKeyNS_AVAILABLE(10_3, 2_0);    // Value is an NSStringFOUNDATION_EXPORT NSString * const NSStreamSOCKSProxyPortKeyNS_AVAILABLE(10_3, 2_0);    // Value is an NSNumberFOUNDATION_EXPORT NSString * const NSStreamSOCKSProxyVersionKeyNS_AVAILABLE(10_3, 2_0);    // Value is one of NSStreamSOCKSProxyVersion4 or NSStreamSOCKSProxyVersion5FOUNDATION_EXPORT NSString * const NSStreamSOCKSProxyUserKeyNS_AVAILABLE(10_3, 2_0);    // Value is an NSStringFOUNDATION_EXPORT NSString * const NSStreamSOCKSProxyPasswordKeyNS_AVAILABLE(10_3, 2_0);    // Value is an NSStringFOUNDATION_EXPORT NSString * const NSStreamSOCKSProxyVersion4NS_AVAILABLE(10_3, 2_0);    // Value for NSStreamSOCKProxyVersionKeyFOUNDATION_EXPORT NSString * const NSStreamSOCKSProxyVersion5NS_AVAILABLE(10_3, 2_0);    // Value for NSStreamSOCKProxyVersionKeyFOUNDATION_EXPORT NSString * const NSStreamDataWrittenToMemoryStreamKeyNS_AVAILABLE(10_3, 2_0);    // Key for obtaining the data written to a memory stream.FOUNDATION_EXPORT NSString * const NSStreamFileCurrentOffsetKeyNS_AVAILABLE(10_3, 2_0);    // Value is an NSNumber representing the current absolute offset of the stream.// NSString constants for error domains.FOUNDATION_EXPORT NSString * const NSStreamSocketSSLErrorDomainNS_AVAILABLE(10_3, 2_0);    // SSL errors are to be interpreted via <Security/SecureTransport.h>FOUNDATION_EXPORT NSString * const NSStreamSOCKSErrorDomainNS_AVAILABLE(10_3, 2_0);// Property key to specify the type of service for the stream.  This// allows the system to properly handle the request with respect to// routing, suspension behavior and other networking related attributes// appropriate for the given service type.  The service types supported// are documented below.FOUNDATION_EXPORT NSString * const NSStreamNetworkServiceType    NS_AVAILABLE(10_7, 4_0);// Supported network service types:FOUNDATION_EXPORT NSString * const NSStreamNetworkServiceTypeVoIP    NS_AVAILABLE(10_7, 4_0);FOUNDATION_EXPORT NSString * const NSStreamNetworkServiceTypeVideo    NS_AVAILABLE(10_7, 5_0);FOUNDATION_EXPORT NSString * const NSStreamNetworkServiceTypeBackground    NS_AVAILABLE(10_7, 5_0);FOUNDATION_EXPORT NSString * const NSStreamNetworkServiceTypeVoice    NS_AVAILABLE(10_7, 5_0);


0 0
原创粉丝点击