1 #import "TNSStreamTransport.h"
2 #import "TTransportException.h"
5 @implementation TNSStreamTransport
7 - (id) initWithInputStream: (NSInputStream *) input
8 outputStream: (NSOutputStream *) output
11 mInput = [input retain];
12 mOutput = [output retain];
16 - (id) initWithInputStream: (NSInputStream *) input
18 return [self initWithInputStream: input outputStream: nil];
21 - (id) initWithOutputStream: (NSOutputStream *) output
23 return [self initWithInputStream: nil outputStream: output];
27 - (int) readAll: (uint8_t *) buf offset: (int) off length: (int) len
32 ret = [mInput read: buf+off+got maxLength: len-got];
34 @throw [TTransportException exceptionWithReason: @"Cannot read. Remote side has closed."];
42 // FIXME:geech:20071019 - make this write all
43 - (void) write: (uint8_t *) data offset: (unsigned int) offset length: (unsigned int) length
45 int result = [mOutput write: data+offset maxLength: length];
47 @throw [TTransportException exceptionWithReason: @"Error writing to transport output stream."
48 error: [mOutput streamError]];
49 } else if (result == 0) {
50 @throw [TTransportException exceptionWithReason: @"End of output stream."];
51 } else if (result != length) {
52 @throw [TTransportException exceptionWithReason: @"Output stream did not write all of our data."];