00001 // Copyright 1997-2005 Omni Development, Inc. All rights reserved. 00002 // 00003 // This software may only be used and reproduced according to the 00004 // terms in the file OmniSourceLicense.html, which should be 00005 // distributed with this project and can also be found at 00006 // <http://www.omnigroup.com/developer/sourcecode/sourcelicense/>. 00007 // 00008 // $Header: svn+ssh://source.omnigroup.com/Source/svn/Omni/tags/SourceRelease_2005-11-18/OmniGroup/Frameworks/OmniNetworking/ONSocketStream.h 66168 2005-07-28 17:34:52Z kc $ 00009 00010 #import <OmniBase/OBObject.h> 00011 00012 @class NSData, NSMutableData; 00013 @class NSMutableArray; 00014 @class NSString; 00015 @class ONSocket; 00016 00017 #import <Foundation/NSString.h> // For NSStringEncoding 00018 00019 @interface ONSocketStream : OBObject 00020 { 00021 ONSocket *socket; 00022 00023 NSMutableData *readBuffer; 00024 BOOL readBufferContainsEOF; 00025 00026 // BOOL socketPushDisabled; 00027 unsigned int writeBufferingCount; // count of nested -beginBuffering / -endBuffering calls 00028 unsigned int totalBufferedBytes; // number of bytes in writeBuffer 00029 unsigned int firstBufferOffset; // number of bytes from first buffer to ignore (not counted in totalBufferedBytes) 00030 NSMutableArray *writeBuffer; // array of NSDatas to write 00031 } 00032 00033 + streamWithSocket:(ONSocket *)aSocket; 00034 - initWithSocket:(ONSocket *)aSocket; 00035 - (ONSocket *)socket; 00036 - (BOOL)isReadable; 00037 00038 - (void)setReadBuffer:(NSMutableData *)aData; 00039 - (void)clearReadBuffer; 00040 - (void)advanceReadBufferBy:(unsigned int)advanceAmount; 00041 00042 - (NSData *)readData; 00043 - (NSData *)readDataOfLength:(unsigned int)length; 00044 - (NSData *)readDataWithMaxLength:(unsigned int)length; 00045 00046 - (unsigned int)readBytesWithMaxLength:(unsigned int)length intoBuffer:(void *)buffer; 00047 - (void)readBytesOfLength:(unsigned int)length intoBuffer:(void *)buffer; 00048 - (BOOL)skipBytes:(unsigned int)length; 00049 00050 - (void)writeData:(NSData *)theData; 00051 00052 // Write buffering. When buffering is enabled, writes are accumulated by the ONSocketStream until either a threshold has been reached or buffering has been turned off. beginBuffering/endBuffering calls must be properly balanced. 00053 - (void)beginBuffering; 00054 - (void)endBuffering; 00055 00056 // String I/O routines. Technically these don't really belong here, and callers should use the more sophisticated character conversion code in OmniFoundation or OWF. However, it's extremely convenient for many internet protocols to be able to do simple string-oriented operations. Callers should be aware that these routines might not behave correctly when dealing with unusual string encodings (anything which doesn't look much like ASCII). 00057 00058 - (NSString *)readString; 00059 // Note: not currently reliable if the stringEncoding is set to a multibyte encoding, because we don't know if a character is split across a buffer boundary. 00060 00061 - (unsigned)getLengthOfNextLine:(unsigned int *)eolBytes; 00062 // Low-level line parsing routine. This returns the number of bytes in the next line, blocking if necessary to read a full EOL marker. If eolBytes is not NULL, it is filled in with the length of the EOL marker; in any case, the EOL marker is included in the return value of this method. This routine is quite liberal in its interpretation of EOL, and should accept most EOL markers seen in practice. It should work with ASCII, the ISO 8859 character sets, and UTF-8 (but not UTF-16 or EBCDIC). Returns 0 at EOF. 00063 00064 - (NSString *)readLineAndAdvance:(BOOL)shouldAdvance; // Reads a line and interprets it as a string according to the current string encoding, returning the result. Does not include any trailing EOL characters. Returns nil at EOF. 00065 - (NSString *)readLine; // equivalent to readLineAndAdvance:YES 00066 - (NSString *)peekLine; // equivalent to readLineAndAdvance:NO 00067 00068 - (void)writeString:(NSString *)aString; 00069 - (void)writeFormat:(NSString *)aFormat, ...; 00070 00071 - (NSStringEncoding)stringEncoding; 00072 - (void)setStringEncoding:(NSStringEncoding)aStringEncoding; 00073 00074 @end