author | Jens Alfke <jens@mooseyard.com> |
Sat May 24 13:26:02 2008 -0700 (2008-05-24) | |
changeset 1 | 8267d5c429c4 |
child 2 | 9fdd8dba529c |
permissions | -rw-r--r-- |
jens@0 | 1 |
// |
jens@0 | 2 |
// TCPStream.h |
jens@0 | 3 |
// MYNetwork |
jens@0 | 4 |
// |
jens@0 | 5 |
// Created by Jens Alfke on 5/10/08. |
jens@0 | 6 |
// Copyright 2008 Jens Alfke. All rights reserved. |
jens@0 | 7 |
// |
jens@0 | 8 |
|
jens@0 | 9 |
#import <Foundation/Foundation.h> |
jens@0 | 10 |
@class TCPConnection, TCPWriter; |
jens@0 | 11 |
|
jens@0 | 12 |
|
jens@0 | 13 |
/** INTERNAL abstract superclass for data streams, used by TCPConnection. */ |
jens@0 | 14 |
@interface TCPStream : NSObject |
jens@0 | 15 |
{ |
jens@0 | 16 |
TCPConnection *_conn; |
jens@0 | 17 |
NSStream *_stream; |
jens@0 | 18 |
BOOL _shouldClose; |
jens@0 | 19 |
} |
jens@0 | 20 |
|
jens@0 | 21 |
- (id) initWithConnection: (TCPConnection*)conn stream: (NSStream*)stream; |
jens@0 | 22 |
|
jens@0 | 23 |
/** The connection's security level as reported by the underlying CFStream. */ |
jens@0 | 24 |
@property (readonly) NSString *securityLevel; |
jens@0 | 25 |
|
jens@0 | 26 |
/** The SSL property dictionary for the CFStream. */ |
jens@0 | 27 |
@property (copy) NSDictionary* SSLProperties; |
jens@0 | 28 |
|
jens@0 | 29 |
/** The SSL certificate(s) of the peer, if any. */ |
jens@0 | 30 |
@property (readonly) NSArray *peerSSLCerts; |
jens@0 | 31 |
|
jens@0 | 32 |
/** Opens the stream. */ |
jens@0 | 33 |
- (void) open; |
jens@0 | 34 |
|
jens@0 | 35 |
/** Disconnects abruptly. */ |
jens@0 | 36 |
- (void) disconnect; |
jens@0 | 37 |
|
jens@0 | 38 |
/** Closes the stream politely, waiting until there's no data pending. */ |
jens@0 | 39 |
- (BOOL) close; |
jens@0 | 40 |
|
jens@0 | 41 |
/** Is the stream open? */ |
jens@0 | 42 |
@property (readonly) BOOL isOpen; |
jens@0 | 43 |
|
jens@0 | 44 |
/** Does the stream have pending data to read or write, that prevents it from closing? */ |
jens@0 | 45 |
@property (readonly) BOOL isBusy; |
jens@0 | 46 |
|
jens@0 | 47 |
/** Generic accessor for CFStream/NSStream properties. */ |
jens@0 | 48 |
- (id) propertyForKey: (CFStringRef)cfStreamProperty; |
jens@0 | 49 |
|
jens@0 | 50 |
/** Generic accessor for CFStream/NSStream properties. */ |
jens@0 | 51 |
- (void) setProperty: (id)value forKey: (CFStringRef)cfStreamProperty; |
jens@0 | 52 |
|
jens@0 | 53 |
@end |
jens@0 | 54 |
|
jens@0 | 55 |
|
jens@0 | 56 |
/** Input stream for a TCPConnection. */ |
jens@0 | 57 |
@interface TCPReader : TCPStream |
jens@0 | 58 |
/** The connection's TCPWriter. */ |
jens@0 | 59 |
@property (readonly) TCPWriter *writer; |
jens@0 | 60 |
@end |
jens@0 | 61 |
|
jens@0 | 62 |
|
jens@0 | 63 |
|
jens@0 | 64 |
@interface TCPStream (Protected) |
jens@0 | 65 |
/** Called when the stream opens. */ |
jens@0 | 66 |
- (void) _opened; |
jens@0 | 67 |
|
jens@0 | 68 |
/** Called when the stream has bytes available to read. */ |
jens@0 | 69 |
- (void) _canRead; |
jens@0 | 70 |
|
jens@0 | 71 |
/** Called when the stream has space available in its output buffer to write to. */ |
jens@0 | 72 |
- (void) _canWrite; |
jens@0 | 73 |
|
jens@0 | 74 |
/** Called when the underlying stream closes due to the socket closing. */ |
jens@0 | 75 |
- (void) _gotEOF; |
jens@0 | 76 |
|
jens@0 | 77 |
/** Call this if a read/write call returns -1 to report an error; |
jens@0 | 78 |
it will look up the error from the NSStream and call gotError: with it. |
jens@0 | 79 |
This method always returns NO, so you can "return [self _gotError]". */ |
jens@0 | 80 |
- (BOOL) _gotError; |
jens@0 | 81 |
|
jens@0 | 82 |
/** Signals a fatal error to the TCPConnection. |
jens@0 | 83 |
This method always returns NO, so you can "return [self _gotError: e]". */ |
jens@0 | 84 |
- (BOOL) _gotError: (NSError*)error; |
jens@0 | 85 |
@end |