git.ithinksw.org
/
ITFoundation.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More socket work
[ITFoundation.git]
/
ITByteStream.m
diff --git
a/ITByteStream.m
b/ITByteStream.m
index
301d851
..
4d34eb0
100755
(executable)
--- a/
ITByteStream.m
+++ b/
ITByteStream.m
@@
-8,7
+8,7
@@
#import "ITByteStream.h"
#import "ITByteStream.h"
-// TODO: Add NSCopying/NSCoding support
+// TODO: Add NSCopying/NSCoding support
. Blocking reads (how would this work? NSConditionLock?)
@implementation ITByteStream
-(id) init
@implementation ITByteStream
-(id) init
@@
-16,6
+16,7
@@
if (self == [super init])
{
data = [[NSMutableData alloc] init];
if (self == [super init])
{
data = [[NSMutableData alloc] init];
+ lock = [[NSLock alloc] init];
}
return self;
}
}
return self;
}
@@
-25,6
+26,7
@@
if (self == [super init])
{
data = [stream->data copy];
if (self == [super init])
{
data = [stream->data copy];
+ lock = [[NSLock alloc] init];
}
return 0;
}
}
return 0;
}
@@
-32,31
+34,50
@@
-(void) dealloc
{
[data release];
-(void) dealloc
{
[data release];
+ [lock release];
[super dealloc];
}
-(int) availableDataLength
{
[super dealloc];
}
-(int) availableDataLength
{
- return [data length];
+ int len;
+ [lock lock];
+ len = [data length];
+ [lock unlock];
+ return len;
}
-(NSData*) readDataOfLength:(int)length
{
NSData *ret, *tmp;
NSRange range = {0, length};
}
-(NSData*) readDataOfLength:(int)length
{
NSData *ret, *tmp;
NSRange range = {0, length};
+ [lock lock];
ret = [data subdataWithRange:range];
#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
ret = [data subdataWithRange:range];
#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
- [data replaceBytesInRange:range withBytes:nil length:0];
// this should delete off the end. should test.
+ [data replaceBytesInRange:range withBytes:nil length:0];
#else
range = {length, [data length]};
tmp = [data subdataWithRange:range];
#else
range = {length, [data length]};
tmp = [data subdataWithRange:range];
- [data setData:tmp];
// maybe i should add a lock to this? it would be bad if someone was writing when it was reading...
+ [data setData:tmp];
#endif
#endif
+ [lock unlock];
+ return ret;
+}
+
+-(NSData*) readAllData
+{
+ NSData *ret;
+ [lock lock];
+ ret = [data autorelease];
+ data = [[NSMutableData alloc] init];
+ [lock unlock];
return ret;
}
-(void) writeData:(NSData*)_data
{
return ret;
}
-(void) writeData:(NSData*)_data
{
+ [lock lock];
[data appendData:_data];
[data appendData:_data];
+ [lock unlock];
}
@end
}
@end