Fixed implicit-retain-self warnings

This commit is contained in:
Pierre-Olivier Latour
2019-01-03 17:14:50 -08:00
parent 0a7d185417
commit 03fae468d1
3 changed files with 79 additions and 80 deletions

View File

@ -1228,7 +1228,6 @@
"-Wno-explicit-ownership-type", "-Wno-explicit-ownership-type",
"-Wno-gnu-statement-expression", "-Wno-gnu-statement-expression",
"-Wno-direct-ivar-access", "-Wno-direct-ivar-access",
"-Wno-implicit-retain-self",
"-Wno-assign-enum", "-Wno-assign-enum",
"-Wno-format-nonliteral", "-Wno-format-nonliteral",
"-Wno-cast-align", "-Wno-cast-align",

View File

@ -236,20 +236,20 @@ static void _ExecuteMainThreadRunLoopSources() {
- (void)willStartConnection:(GCDWebServerConnection*)connection { - (void)willStartConnection:(GCDWebServerConnection*)connection {
dispatch_sync(_syncQueue, ^{ dispatch_sync(_syncQueue, ^{
GWS_DCHECK(_activeConnections >= 0); GWS_DCHECK(self->_activeConnections >= 0);
if (_activeConnections == 0) { if (self->_activeConnections == 0) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (_disconnectTimer) { if (self->_disconnectTimer) {
CFRunLoopTimerInvalidate(_disconnectTimer); CFRunLoopTimerInvalidate(self->_disconnectTimer);
CFRelease(_disconnectTimer); CFRelease(self->_disconnectTimer);
_disconnectTimer = NULL; self->_disconnectTimer = NULL;
} }
if (_connected == NO) { if (self->_connected == NO) {
[self _didConnect]; [self _didConnect];
} }
}); });
} }
_activeConnections += 1; self->_activeConnections += 1;
}); });
} }
@ -288,22 +288,22 @@ static void _ExecuteMainThreadRunLoopSources() {
- (void)didEndConnection:(GCDWebServerConnection*)connection { - (void)didEndConnection:(GCDWebServerConnection*)connection {
dispatch_sync(_syncQueue, ^{ dispatch_sync(_syncQueue, ^{
GWS_DCHECK(_activeConnections > 0); GWS_DCHECK(self->_activeConnections > 0);
_activeConnections -= 1; self->_activeConnections -= 1;
if (_activeConnections == 0) { if (self->_activeConnections == 0) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if ((_disconnectDelay > 0.0) && (_source4 != NULL)) { if ((self->_disconnectDelay > 0.0) && (self->_source4 != NULL)) {
if (_disconnectTimer) { if (self->_disconnectTimer) {
CFRunLoopTimerInvalidate(_disconnectTimer); CFRunLoopTimerInvalidate(self->_disconnectTimer);
CFRelease(_disconnectTimer); CFRelease(self->_disconnectTimer);
} }
_disconnectTimer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + _disconnectDelay, 0.0, 0, 0, ^(CFRunLoopTimerRef timer) { self->_disconnectTimer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + self->_disconnectDelay, 0.0, 0, 0, ^(CFRunLoopTimerRef timer) {
GWS_DCHECK([NSThread isMainThread]); GWS_DCHECK([NSThread isMainThread]);
[self _didDisconnect]; [self _didDisconnect];
CFRelease(_disconnectTimer); CFRelease(self->_disconnectTimer);
_disconnectTimer = NULL; self->_disconnectTimer = NULL;
}); });
CFRunLoopAddTimer(CFRunLoopGetMain(), _disconnectTimer, kCFRunLoopCommonModes); CFRunLoopAddTimer(CFRunLoopGetMain(), self->_disconnectTimer, kCFRunLoopCommonModes);
} else { } else {
[self _didDisconnect]; [self _didDisconnect];
} }
@ -473,7 +473,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
GWS_LOG_DEBUG(@"Did close %s listening socket %i", isIPv6 ? "IPv6" : "IPv4", listeningSocket); GWS_LOG_DEBUG(@"Did close %s listening socket %i", isIPv6 ? "IPv6" : "IPv4", listeningSocket);
} }
} }
dispatch_group_leave(_sourceGroup); dispatch_group_leave(self->_sourceGroup);
}); });
dispatch_source_set_event_handler(source, ^{ dispatch_source_set_event_handler(source, ^{
@autoreleasepool { @autoreleasepool {
@ -496,7 +496,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
int noSigPipe = 1; int noSigPipe = 1;
setsockopt(socket, SOL_SOCKET, SO_NOSIGPIPE, &noSigPipe, sizeof(noSigPipe)); // Make sure this socket cannot generate SIG_PIPE setsockopt(socket, SOL_SOCKET, SO_NOSIGPIPE, &noSigPipe, sizeof(noSigPipe)); // Make sure this socket cannot generate SIG_PIPE
GCDWebServerConnection* connection = [(GCDWebServerConnection*)[_connectionClass alloc] initWithServer:self localAddress:localAddress remoteAddress:remoteAddress socket:socket]; // Connection will automatically retain itself while opened GCDWebServerConnection* connection = [(GCDWebServerConnection*)[self->_connectionClass alloc] initWithServer:self localAddress:localAddress remoteAddress:remoteAddress socket:socket]; // Connection will automatically retain itself while opened
[connection self]; // Prevent compiler from complaining about unused variable / useless statement [connection self]; // Prevent compiler from complaining about unused variable / useless statement
} else { } else {
GWS_LOG_ERROR(@"Failed accepting %s socket: %s (%i)", isIPv6 ? "IPv6" : "IPv4", strerror(errno), errno); GWS_LOG_ERROR(@"Failed accepting %s socket: %s (%i)", isIPv6 ? "IPv6" : "IPv4", strerror(errno), errno);
@ -552,14 +552,14 @@ static inline NSString* _EncodeBase64(NSString* string) {
_authenticationBasicAccounts = [[NSMutableDictionary alloc] init]; _authenticationBasicAccounts = [[NSMutableDictionary alloc] init];
NSDictionary* accounts = _GetOption(_options, GCDWebServerOption_AuthenticationAccounts, @{}); NSDictionary* accounts = _GetOption(_options, GCDWebServerOption_AuthenticationAccounts, @{});
[accounts enumerateKeysAndObjectsUsingBlock:^(NSString* username, NSString* password, BOOL* stop) { [accounts enumerateKeysAndObjectsUsingBlock:^(NSString* username, NSString* password, BOOL* stop) {
[_authenticationBasicAccounts setObject:_EncodeBase64([NSString stringWithFormat:@"%@:%@", username, password]) forKey:username]; [self->_authenticationBasicAccounts setObject:_EncodeBase64([NSString stringWithFormat:@"%@:%@", username, password]) forKey:username];
}]; }];
} else if ([authenticationMethod isEqualToString:GCDWebServerAuthenticationMethod_DigestAccess]) { } else if ([authenticationMethod isEqualToString:GCDWebServerAuthenticationMethod_DigestAccess]) {
_authenticationRealm = [(NSString*)_GetOption(_options, GCDWebServerOption_AuthenticationRealm, _serverName) copy]; _authenticationRealm = [(NSString*)_GetOption(_options, GCDWebServerOption_AuthenticationRealm, _serverName) copy];
_authenticationDigestAccounts = [[NSMutableDictionary alloc] init]; _authenticationDigestAccounts = [[NSMutableDictionary alloc] init];
NSDictionary* accounts = _GetOption(_options, GCDWebServerOption_AuthenticationAccounts, @{}); NSDictionary* accounts = _GetOption(_options, GCDWebServerOption_AuthenticationAccounts, @{});
[accounts enumerateKeysAndObjectsUsingBlock:^(NSString* username, NSString* password, BOOL* stop) { [accounts enumerateKeysAndObjectsUsingBlock:^(NSString* username, NSString* password, BOOL* stop) {
[_authenticationDigestAccounts setObject:GCDWebServerComputeMD5Digest(@"%@:%@:%@", username, _authenticationRealm, password) forKey:username]; [self->_authenticationDigestAccounts setObject:GCDWebServerComputeMD5Digest(@"%@:%@:%@", username, self->_authenticationRealm, password) forKey:username];
}]; }];
} }
_connectionClass = _GetOption(_options, GCDWebServerOption_ConnectionClass, [GCDWebServerConnection class]); _connectionClass = _GetOption(_options, GCDWebServerOption_ConnectionClass, [GCDWebServerConnection class]);
@ -624,7 +624,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
GWS_LOG_INFO(@"%@ started on port %i and reachable at %@", [self class], (int)_port, self.serverURL); GWS_LOG_INFO(@"%@ started on port %i and reachable at %@", [self class], (int)_port, self.serverURL);
if ([_delegate respondsToSelector:@selector(webServerDidStart:)]) { if ([_delegate respondsToSelector:@selector(webServerDidStart:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate webServerDidStart:self]; [self->_delegate webServerDidStart:self];
}); });
} }
@ -685,10 +685,10 @@ static inline NSString* _EncodeBase64(NSString* string) {
_authenticationDigestAccounts = nil; _authenticationDigestAccounts = nil;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (_disconnectTimer) { if (self->_disconnectTimer) {
CFRunLoopTimerInvalidate(_disconnectTimer); CFRunLoopTimerInvalidate(self->_disconnectTimer);
CFRelease(_disconnectTimer); CFRelease(self->_disconnectTimer);
_disconnectTimer = NULL; self->_disconnectTimer = NULL;
[self _didDisconnect]; [self _didDisconnect];
} }
}); });
@ -696,7 +696,7 @@ static inline NSString* _EncodeBase64(NSString* string) {
GWS_LOG_INFO(@"%@ stopped", [self class]); GWS_LOG_INFO(@"%@ stopped", [self class]);
if ([_delegate respondsToSelector:@selector(webServerDidStop:)]) { if ([_delegate respondsToSelector:@selector(webServerDidStop:)]) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate webServerDidStop:self]; [self->_delegate webServerDidStop:self];
}); });
} }
} }

View File

@ -193,17 +193,17 @@ NS_ASSUME_NONNULL_END
CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Transfer-Encoding"), CFSTR("chunked")); CFHTTPMessageSetHeaderFieldValue(_responseMessage, CFSTR("Transfer-Encoding"), CFSTR("chunked"));
} }
[_response.additionalHeaders enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL* stop) { [_response.additionalHeaders enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL* stop) {
CFHTTPMessageSetHeaderFieldValue(_responseMessage, (__bridge CFStringRef)key, (__bridge CFStringRef)obj); CFHTTPMessageSetHeaderFieldValue(self->_responseMessage, (__bridge CFStringRef)key, (__bridge CFStringRef)obj);
}]; }];
[self writeHeadersWithCompletionBlock:^(BOOL success) { [self writeHeadersWithCompletionBlock:^(BOOL success) {
if (success) { if (success) {
if (hasBody) { if (hasBody) {
[self writeBodyWithCompletionBlock:^(BOOL successInner) { [self writeBodyWithCompletionBlock:^(BOOL successInner) {
[_response performClose]; // TODO: There's nothing we can do on failure as headers have already been sent [self->_response performClose]; // TODO: There's nothing we can do on failure as headers have already been sent
}]; }];
} }
} else if (hasBody) { } else if (hasBody) {
[_response performClose]; [self->_response performClose];
} }
}]; }];
} else { } else {
@ -235,11 +235,11 @@ NS_ASSUME_NONNULL_END
[self readBodyWithRemainingLength:length [self readBodyWithRemainingLength:length
completionBlock:^(BOOL success) { completionBlock:^(BOOL success) {
NSError* localError = nil; NSError* localError = nil;
if ([_request performClose:&localError]) { if ([self->_request performClose:&localError]) {
[self _startProcessingRequest]; [self _startProcessingRequest];
} else { } else {
GWS_LOG_ERROR(@"Failed closing request body for socket %i: %@", _socket, error); GWS_LOG_ERROR(@"Failed closing request body for socket %i: %@", self->_socket, error);
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError]; [self abortRequest:self->_request withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError];
} }
}]; }];
} else { } else {
@ -264,11 +264,11 @@ NS_ASSUME_NONNULL_END
[self readNextBodyChunk:chunkData [self readNextBodyChunk:chunkData
completionBlock:^(BOOL success) { completionBlock:^(BOOL success) {
NSError* localError = nil; NSError* localError = nil;
if ([_request performClose:&localError]) { if ([self->_request performClose:&localError]) {
[self _startProcessingRequest]; [self _startProcessingRequest];
} else { } else {
GWS_LOG_ERROR(@"Failed closing request body for socket %i: %@", _socket, error); GWS_LOG_ERROR(@"Failed closing request body for socket %i: %@", self->_socket, error);
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError]; [self abortRequest:self->_request withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError];
} }
}]; }];
} }
@ -279,13 +279,13 @@ NS_ASSUME_NONNULL_END
[self readHeaders:headersData [self readHeaders:headersData
withCompletionBlock:^(NSData* extraData) { withCompletionBlock:^(NSData* extraData) {
if (extraData) { if (extraData) {
NSString* requestMethod = CFBridgingRelease(CFHTTPMessageCopyRequestMethod(_requestMessage)); // Method verbs are case-sensitive and uppercase NSString* requestMethod = CFBridgingRelease(CFHTTPMessageCopyRequestMethod(self->_requestMessage)); // Method verbs are case-sensitive and uppercase
if (_server.shouldAutomaticallyMapHEADToGET && [requestMethod isEqualToString:@"HEAD"]) { if (self->_server.shouldAutomaticallyMapHEADToGET && [requestMethod isEqualToString:@"HEAD"]) {
requestMethod = @"GET"; requestMethod = @"GET";
_virtualHEAD = YES; self->_virtualHEAD = YES;
} }
NSDictionary* requestHeaders = CFBridgingRelease(CFHTTPMessageCopyAllHeaderFields(_requestMessage)); // Header names are case-insensitive but CFHTTPMessageCopyAllHeaderFields() will standardize the common ones NSDictionary* requestHeaders = CFBridgingRelease(CFHTTPMessageCopyAllHeaderFields(self->_requestMessage)); // Header names are case-insensitive but CFHTTPMessageCopyAllHeaderFields() will standardize the common ones
NSURL* requestURL = CFBridgingRelease(CFHTTPMessageCopyRequestURL(_requestMessage)); NSURL* requestURL = CFBridgingRelease(CFHTTPMessageCopyRequestURL(self->_requestMessage));
if (requestURL) { if (requestURL) {
requestURL = [self rewriteRequestURL:requestURL withMethod:requestMethod headers:requestHeaders]; requestURL = [self rewriteRequestURL:requestURL withMethod:requestMethod headers:requestHeaders];
GWS_DCHECK(requestURL); GWS_DCHECK(requestURL);
@ -298,53 +298,53 @@ NS_ASSUME_NONNULL_END
NSString* queryString = requestURL ? CFBridgingRelease(CFURLCopyQueryString((CFURLRef)requestURL, NULL)) : nil; // Don't use -[NSURL query] to make sure query is not unescaped; NSString* queryString = requestURL ? CFBridgingRelease(CFURLCopyQueryString((CFURLRef)requestURL, NULL)) : nil; // Don't use -[NSURL query] to make sure query is not unescaped;
NSDictionary* requestQuery = queryString ? GCDWebServerParseURLEncodedForm(queryString) : @{}; NSDictionary* requestQuery = queryString ? GCDWebServerParseURLEncodedForm(queryString) : @{};
if (requestMethod && requestURL && requestHeaders && requestPath && requestQuery) { if (requestMethod && requestURL && requestHeaders && requestPath && requestQuery) {
for (_handler in _server.handlers) { for (self->_handler in self->_server.handlers) {
_request = _handler.matchBlock(requestMethod, requestURL, requestHeaders, requestPath, requestQuery); self->_request = self->_handler.matchBlock(requestMethod, requestURL, requestHeaders, requestPath, requestQuery);
if (_request) { if (self->_request) {
break; break;
} }
} }
if (_request) { if (self->_request) {
_request.localAddressData = self.localAddressData; self->_request.localAddressData = self.localAddressData;
_request.remoteAddressData = self.remoteAddressData; self->_request.remoteAddressData = self.remoteAddressData;
if ([_request hasBody]) { if ([self->_request hasBody]) {
[_request prepareForWriting]; [self->_request prepareForWriting];
if (_request.usesChunkedTransferEncoding || (extraData.length <= _request.contentLength)) { if (self->_request.usesChunkedTransferEncoding || (extraData.length <= self->_request.contentLength)) {
NSString* expectHeader = [requestHeaders objectForKey:@"Expect"]; NSString* expectHeader = [requestHeaders objectForKey:@"Expect"];
if (expectHeader) { if (expectHeader) {
if ([expectHeader caseInsensitiveCompare:@"100-continue"] == NSOrderedSame) { // TODO: Actually validate request before continuing if ([expectHeader caseInsensitiveCompare:@"100-continue"] == NSOrderedSame) { // TODO: Actually validate request before continuing
[self writeData:_continueData [self writeData:_continueData
withCompletionBlock:^(BOOL success) { withCompletionBlock:^(BOOL success) {
if (success) { if (success) {
if (_request.usesChunkedTransferEncoding) { if (self->_request.usesChunkedTransferEncoding) {
[self _readChunkedBodyWithInitialData:extraData]; [self _readChunkedBodyWithInitialData:extraData];
} else { } else {
[self _readBodyWithLength:_request.contentLength initialData:extraData]; [self _readBodyWithLength:self->_request.contentLength initialData:extraData];
} }
} }
}]; }];
} else { } else {
GWS_LOG_ERROR(@"Unsupported 'Expect' / 'Content-Length' header combination on socket %i", _socket); GWS_LOG_ERROR(@"Unsupported 'Expect' / 'Content-Length' header combination on socket %i", self->_socket);
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_ExpectationFailed]; [self abortRequest:self->_request withStatusCode:kGCDWebServerHTTPStatusCode_ExpectationFailed];
} }
} else { } else {
if (_request.usesChunkedTransferEncoding) { if (self->_request.usesChunkedTransferEncoding) {
[self _readChunkedBodyWithInitialData:extraData]; [self _readChunkedBodyWithInitialData:extraData];
} else { } else {
[self _readBodyWithLength:_request.contentLength initialData:extraData]; [self _readBodyWithLength:self->_request.contentLength initialData:extraData];
} }
} }
} else { } else {
GWS_LOG_ERROR(@"Unexpected 'Content-Length' header value on socket %i", _socket); GWS_LOG_ERROR(@"Unexpected 'Content-Length' header value on socket %i", self->_socket);
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_BadRequest]; [self abortRequest:self->_request withStatusCode:kGCDWebServerHTTPStatusCode_BadRequest];
} }
} else { } else {
[self _startProcessingRequest]; [self _startProcessingRequest];
} }
} else { } else {
_request = [[GCDWebServerRequest alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:requestPath query:requestQuery]; self->_request = [[GCDWebServerRequest alloc] initWithMethod:requestMethod url:requestURL headers:requestHeaders path:requestPath query:requestQuery];
GWS_DCHECK(_request); GWS_DCHECK(self->_request);
[self abortRequest:_request withStatusCode:kGCDWebServerHTTPStatusCode_NotImplemented]; [self abortRequest:self->_request withStatusCode:kGCDWebServerHTTPStatusCode_NotImplemented];
} }
} else { } else {
[self abortRequest:nil withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError]; [self abortRequest:nil withStatusCode:kGCDWebServerHTTPStatusCode_InternalServerError];
@ -426,15 +426,15 @@ NS_ASSUME_NONNULL_END
[self didReadBytes:((char*)data.bytes + originalLength) length:(data.length - originalLength)]; [self didReadBytes:((char*)data.bytes + originalLength) length:(data.length - originalLength)];
block(YES); block(YES);
} else { } else {
if (_totalBytesRead > 0) { if (self->_totalBytesRead > 0) {
GWS_LOG_ERROR(@"No more data available on socket %i", _socket); GWS_LOG_ERROR(@"No more data available on socket %i", self->_socket);
} else { } else {
GWS_LOG_WARNING(@"No data received from socket %i", _socket); GWS_LOG_WARNING(@"No data received from socket %i", self->_socket);
} }
block(NO); block(NO);
} }
} else { } else {
GWS_LOG_ERROR(@"Error while reading from socket %i: %s (%i)", _socket, strerror(error), error); GWS_LOG_ERROR(@"Error while reading from socket %i: %s (%i)", self->_socket, strerror(error), error);
block(NO); block(NO);
} }
} }
@ -452,15 +452,15 @@ NS_ASSUME_NONNULL_END
[self readHeaders:headersData withCompletionBlock:block]; [self readHeaders:headersData withCompletionBlock:block];
} else { } else {
NSUInteger length = range.location + range.length; NSUInteger length = range.location + range.length;
if (CFHTTPMessageAppendBytes(_requestMessage, headersData.bytes, length)) { if (CFHTTPMessageAppendBytes(self->_requestMessage, headersData.bytes, length)) {
if (CFHTTPMessageIsHeaderComplete(_requestMessage)) { if (CFHTTPMessageIsHeaderComplete(self->_requestMessage)) {
block([headersData subdataWithRange:NSMakeRange(length, headersData.length - length)]); block([headersData subdataWithRange:NSMakeRange(length, headersData.length - length)]);
} else { } else {
GWS_LOG_ERROR(@"Failed parsing request headers from socket %i", _socket); GWS_LOG_ERROR(@"Failed parsing request headers from socket %i", self->_socket);
block(nil); block(nil);
} }
} else { } else {
GWS_LOG_ERROR(@"Failed appending request headers data from socket %i", _socket); GWS_LOG_ERROR(@"Failed appending request headers data from socket %i", self->_socket);
block(nil); block(nil);
} }
} }
@ -479,7 +479,7 @@ NS_ASSUME_NONNULL_END
if (success) { if (success) {
if (bodyData.length <= length) { if (bodyData.length <= length) {
NSError* error = nil; NSError* error = nil;
if ([_request performWriteData:bodyData error:&error]) { if ([self->_request performWriteData:bodyData error:&error]) {
NSUInteger remainingLength = length - bodyData.length; NSUInteger remainingLength = length - bodyData.length;
if (remainingLength) { if (remainingLength) {
[self readBodyWithRemainingLength:remainingLength completionBlock:block]; [self readBodyWithRemainingLength:remainingLength completionBlock:block];
@ -487,11 +487,11 @@ NS_ASSUME_NONNULL_END
block(YES); block(YES);
} }
} else { } else {
GWS_LOG_ERROR(@"Failed writing request body on socket %i: %@", _socket, error); GWS_LOG_ERROR(@"Failed writing request body on socket %i: %@", self->_socket, error);
block(NO); block(NO);
} }
} else { } else {
GWS_LOG_ERROR(@"Unexpected extra content reading request body on socket %i", _socket); GWS_LOG_ERROR(@"Unexpected extra content reading request body on socket %i", self->_socket);
block(NO); block(NO);
GWS_DNOT_REACHED(); GWS_DNOT_REACHED();
} }
@ -580,7 +580,7 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
[self didWriteBytes:data.bytes length:data.length]; [self didWriteBytes:data.bytes length:data.length];
block(YES); block(YES);
} else { } else {
GWS_LOG_ERROR(@"Error while writing to socket %i: %s (%i)", _socket, strerror(error), error); GWS_LOG_ERROR(@"Error while writing to socket %i: %s (%i)", self->_socket, strerror(error), error);
block(NO); block(NO);
} }
} }
@ -602,12 +602,12 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
[_response performReadDataWithCompletion:^(NSData* data, NSError* error) { [_response performReadDataWithCompletion:^(NSData* data, NSError* error) {
if (data) { if (data) {
if (data.length) { if (data.length) {
if (_response.usesChunkedTransferEncoding) { if (self->_response.usesChunkedTransferEncoding) {
const char* hexString = [[NSString stringWithFormat:@"%lx", (unsigned long)data.length] UTF8String]; const char* hexString = [[NSString stringWithFormat:@"%lx", (unsigned long)data.length] UTF8String];
size_t hexLength = strlen(hexString); size_t hexLength = strlen(hexString);
NSData* chunk = [NSMutableData dataWithLength:(hexLength + 2 + data.length + 2)]; NSData* chunk = [NSMutableData dataWithLength:(hexLength + 2 + data.length + 2)];
if (chunk == nil) { if (chunk == nil) {
GWS_LOG_ERROR(@"Failed allocating memory for response body chunk for socket %i: %@", _socket, error); GWS_LOG_ERROR(@"Failed allocating memory for response body chunk for socket %i: %@", self->_socket, error);
block(NO); block(NO);
return; return;
} }
@ -631,7 +631,7 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
} }
}]; }];
} else { } else {
if (_response.usesChunkedTransferEncoding) { if (self->_response.usesChunkedTransferEncoding) {
[self writeData:_lastChunkData [self writeData:_lastChunkData
withCompletionBlock:^(BOOL success) { withCompletionBlock:^(BOOL success) {
block(success); block(success);
@ -641,7 +641,7 @@ static inline NSUInteger _ScanHexNumber(const void* bytes, NSUInteger size) {
} }
} }
} else { } else {
GWS_LOG_ERROR(@"Failed reading response body for socket %i: %@", _socket, error); GWS_LOG_ERROR(@"Failed reading response body for socket %i: %@", self->_socket, error);
block(NO); block(NO);
} }
}]; }];