X-Git-Url: http://git.ithinksw.org/ITFoundation.git/blobdiff_plain/f53b25adbb0e87abd41713a586d3c723ebeb8ff0..68089b190f6a03c185722c8532197dacabf52f8d:/ITChunkedByteStream.m diff --git a/ITChunkedByteStream.m b/ITChunkedByteStream.m index 1299503..cb31795 100755 --- a/ITChunkedByteStream.m +++ b/ITChunkedByteStream.m @@ -10,5 +10,54 @@ @implementation ITChunkedByteStream +-initWithDelegate:(id)d +{ + if (self = [super init]) { + q = [[ArrayQueue alloc] init]; + lock = [[NSLock alloc] init]; + delegate = [d retain]; + } + return self; +} +-(BOOL)empty +{ + BOOL a; + [lock lock]; + a = [q isEmpty]; + [lock unlock]; + return a; +} + +-(NSData*) readData +{ + NSData *d; + [lock lock]; + d = (NSData*)[q dequeue]; + [lock unlock]; + return d; +} + +-(oneway void) writeData:(in NSData*)d +{ + [lock lock]; + [q enqueue:d]; + [lock unlock]; +} + +-(oneway void) writeBytesNoCopy:(in char *)b len:(unsigned long)length +{ + [lock lock]; + [q enqueue:[NSData dataWithBytesNoCopy:b length:length]]; + [lock unlock]; +} + +-(oneway void) writeBytes:(in char *)b len:(unsigned long)length +{ + [lock lock]; + [q enqueue:[NSData dataWithBytes:b length:length]]; + [lock unlock]; +} +-delegate {return delegate;} +-setDelegate:(id)d {id old = delegate; [delegate release]; delegate = [d retain]; return old;} @end