1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/TCP/TCPStream.h Sat May 24 13:26:02 2008 -0700
1.3 @@ -0,0 +1,85 @@
1.4 +//
1.5 +// TCPStream.h
1.6 +// MYNetwork
1.7 +//
1.8 +// Created by Jens Alfke on 5/10/08.
1.9 +// Copyright 2008 Jens Alfke. All rights reserved.
1.10 +//
1.11 +
1.12 +#import <Foundation/Foundation.h>
1.13 +@class TCPConnection, TCPWriter;
1.14 +
1.15 +
1.16 +/** INTERNAL abstract superclass for data streams, used by TCPConnection. */
1.17 +@interface TCPStream : NSObject
1.18 +{
1.19 + TCPConnection *_conn;
1.20 + NSStream *_stream;
1.21 + BOOL _shouldClose;
1.22 +}
1.23 +
1.24 +- (id) initWithConnection: (TCPConnection*)conn stream: (NSStream*)stream;
1.25 +
1.26 +/** The connection's security level as reported by the underlying CFStream. */
1.27 +@property (readonly) NSString *securityLevel;
1.28 +
1.29 +/** The SSL property dictionary for the CFStream. */
1.30 +@property (copy) NSDictionary* SSLProperties;
1.31 +
1.32 +/** The SSL certificate(s) of the peer, if any. */
1.33 +@property (readonly) NSArray *peerSSLCerts;
1.34 +
1.35 +/** Opens the stream. */
1.36 +- (void) open;
1.37 +
1.38 +/** Disconnects abruptly. */
1.39 +- (void) disconnect;
1.40 +
1.41 +/** Closes the stream politely, waiting until there's no data pending. */
1.42 +- (BOOL) close;
1.43 +
1.44 +/** Is the stream open? */
1.45 +@property (readonly) BOOL isOpen;
1.46 +
1.47 +/** Does the stream have pending data to read or write, that prevents it from closing? */
1.48 +@property (readonly) BOOL isBusy;
1.49 +
1.50 +/** Generic accessor for CFStream/NSStream properties. */
1.51 +- (id) propertyForKey: (CFStringRef)cfStreamProperty;
1.52 +
1.53 +/** Generic accessor for CFStream/NSStream properties. */
1.54 +- (void) setProperty: (id)value forKey: (CFStringRef)cfStreamProperty;
1.55 +
1.56 +@end
1.57 +
1.58 +
1.59 +/** Input stream for a TCPConnection. */
1.60 +@interface TCPReader : TCPStream
1.61 +/** The connection's TCPWriter. */
1.62 +@property (readonly) TCPWriter *writer;
1.63 +@end
1.64 +
1.65 +
1.66 +
1.67 +@interface TCPStream (Protected)
1.68 +/** Called when the stream opens. */
1.69 +- (void) _opened;
1.70 +
1.71 +/** Called when the stream has bytes available to read. */
1.72 +- (void) _canRead;
1.73 +
1.74 +/** Called when the stream has space available in its output buffer to write to. */
1.75 +- (void) _canWrite;
1.76 +
1.77 +/** Called when the underlying stream closes due to the socket closing. */
1.78 +- (void) _gotEOF;
1.79 +
1.80 +/** Call this if a read/write call returns -1 to report an error;
1.81 + it will look up the error from the NSStream and call gotError: with it.
1.82 + This method always returns NO, so you can "return [self _gotError]". */
1.83 +- (BOOL) _gotError;
1.84 +
1.85 +/** Signals a fatal error to the TCPConnection.
1.86 + This method always returns NO, so you can "return [self _gotError: e]". */
1.87 +- (BOOL) _gotError: (NSError*)error;
1.88 +@end