Added -[TCPConnection initToNetService:] to make it easier to use with Bonjour. This allowed me to simplify BLIPEchoClient quite a lot.
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 /** Generic accessor for CFStream/NSStream properties. */
51 - (id) propertyForKey: (CFStringRef)cfStreamProperty;
53 /** Generic accessor for CFStream/NSStream properties. */
54 - (void) setProperty: (id)value forKey: (CFStringRef)cfStreamProperty;
59 /** Input stream for a TCPConnection. */
60 @interface TCPReader : TCPStream
62 /** The connection's TCPWriter. */
63 @property (readonly) TCPWriter *writer;
65 /** Reads bytes from the stream, like the corresponding method of NSInputStream.
66 The number of bytes actually read is returned, or zero if no data is available.
67 If an error occurs, it will call its -_gotError method, and return a negative number. */
68 - (NSInteger) read: (void*)dst maxLength: (NSUInteger)maxLength;
74 @interface TCPStream (Protected)
75 /** Called when the stream opens. */
78 /** Called when the stream has bytes available to read. */
81 /** Called when the stream has space available in its output buffer to write to. */
84 /** Called when the underlying stream closes due to the socket closing. */
87 /** Call this if a read/write call returns -1 to report an error;
88 it will look up the error from the NSStream and call gotError: with it.
89 This method always returns NO, so you can "return [self _gotError]". */
92 /** Signals a fatal error to the TCPConnection.
93 This method always returns NO, so you can "return [self _gotError: e]". */
94 - (BOOL) _gotError: (NSError*)error;