Made C99 project default.
5 // Created by Jens Alfke on 5/10/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
9 #import <Foundation/Foundation.h>
10 @class TCPConnection, TCPWriter, IPAddress;
13 /** Abstract superclass for data streams, used by TCPConnection. */
14 @interface TCPStream : NSObject
21 - (id) initWithConnection: (TCPConnection*)conn stream: (NSStream*)stream;
23 /** The IP address this stream is connected to. */
24 @property (readonly) IPAddress *peerAddress;
26 /** The connection's security level as reported by the underlying CFStream. */
27 @property (readonly) NSString *securityLevel;
29 /** The SSL property dictionary for the CFStream. */
30 @property (copy) NSDictionary* SSLProperties;
32 /** The SSL certificate(s) of the peer, if any. */
33 @property (readonly) NSArray *peerSSLCerts;
35 /** Opens the stream. */
38 /** Disconnects abruptly. */
41 /** Closes the stream politely, waiting until there's no data pending. */
44 /** Is the stream open? */
45 @property (readonly) BOOL isOpen;
47 /** Does the stream have pending data to read or write, that prevents it from closing? */
48 @property (readonly) BOOL isBusy;
50 /** Returns NO if the stream is ready to close (-close has been called and -isBusy is NO.) */
51 @property (readonly) BOOL isActive;
53 /** Generic accessor for CFStream/NSStream properties. */
54 - (id) propertyForKey: (CFStringRef)cfStreamProperty;
56 /** Generic accessor for CFStream/NSStream properties. */
57 - (void) setProperty: (id)value forKey: (CFStringRef)cfStreamProperty;
62 /** Input stream for a TCPConnection. */
63 @interface TCPReader : TCPStream
65 /** The connection's TCPWriter. */
66 @property (readonly) TCPWriter *writer;
68 /** Reads bytes from the stream, like the corresponding method of NSInputStream.
69 The number of bytes actually read is returned, or zero if no data is available.
70 If an error occurs, it will call its -_gotError method, and return a negative number. */
71 - (NSInteger) read: (void*)dst maxLength: (NSUInteger)maxLength;
77 @interface TCPStream (Protected)
78 /** Called when the stream opens. */
81 /** Called when the stream has bytes available to read. */
84 /** Called when the stream has space available in its output buffer to write to. */
87 /** Called when the underlying stream closes due to the socket closing. */
90 /** Call this if a read/write call returns -1 to report an error;
91 it will look up the error from the NSStream and call gotError: with it.
92 This method always returns NO, so you can "return [self _gotError]". */
95 /** Signals a fatal error to the TCPConnection.
96 This method always returns NO, so you can "return [self _gotError: e]". */
97 - (BOOL) _gotError: (NSError*)error;