Added GCDWebServerBodyWriter protocol

This commit is contained in:
Pierre-Olivier Latour
2014-04-06 12:09:44 -07:00
parent 1f9a0d38d0
commit 63a66ff331
11 changed files with 131 additions and 69 deletions
+10 -6
View File
@@ -44,19 +44,23 @@
ARC_DEALLOC(super);
}
- (BOOL)open {
- (BOOL)open:(NSError**)error {
DCHECK(_data == nil);
_data = [[NSMutableData alloc] initWithCapacity:self.contentLength];
return _data ? YES : NO;
if (_data == nil) {
*error = [NSError errorWithDomain:kGCDWebServerErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Failed allocating memory"}];
return NO;
}
return YES;
}
- (NSInteger)write:(const void*)buffer maxLength:(NSUInteger)length {
- (BOOL)writeData:(NSData*)data error:(NSError**)error {
DCHECK(_data != nil);
[_data appendBytes:buffer length:length];
return length;
[_data appendData:data];
return YES;
}
- (BOOL)close {
- (BOOL)close:(NSError**)error {
DCHECK(_data != nil);
return YES;
}