Skip to content

Commit

Permalink
Fix all new warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
nlutsenko committed Jul 6, 2016
1 parent a944d5f commit eda51ab
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 44 deletions.
36 changes: 18 additions & 18 deletions SocketRocket/Internal/Proxy/SRProxyConnect.m
Expand Up @@ -231,21 +231,18 @@ - (void)_fetchPAC:(NSURL *)PACurl
[self _openConnection];
return;
}
__weak typeof(self) weakSelf = self;
__weak typeof(self) wself = self;
NSURLRequest *request = [NSURLRequest requestWithURL:PACurl];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error) {
NSString* script = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[weakSelf _runPACScript:script];
} else {
[weakSelf _openConnection];
}

}];
[task resume];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
__strong typeof(wself) sself = wself;
if (!error) {
NSString *script = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[sself _runPACScript:script];
} else {
[sself _openConnection];
}
}] resume];
}

- (void)_runPACScript:(NSString *)script
Expand Down Expand Up @@ -360,6 +357,8 @@ - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode;
[self _processInputStream];
}
} break;
case NSStreamEventHasSpaceAvailable:
case NSStreamEventNone:
default:
SRDebugLog(@"(default) %@", aStream);
break;
Expand Down Expand Up @@ -448,13 +447,14 @@ - (void)_proxyHTTPHeadersDidFinish
- (void)_writeData:(NSData *)data
{
const uint8_t * bytes = data.bytes;
__block NSInteger timeout = SRProxyConnectWriteTimeout * 1000000; // wait timeout before giving up
__block NSInteger timeout = (NSInteger)(SRProxyConnectWriteTimeout * 1000000); // wait timeout before giving up
__weak typeof(self) wself = self;
dispatch_async(_writeQueue, ^{
if (!wself) {
__strong typeof(wself) sself = self;
if (!sself) {
return;
}
NSOutputStream *outStream = wself.outputStream;
NSOutputStream *outStream = sself.outputStream;
if (!outStream) {
return;
}
Expand All @@ -463,9 +463,9 @@ - (void)_writeData:(NSData *)data
timeout -= 100;
if (timeout < 0) {
NSError *error = SRHTTPErrorWithCodeDescription(408, 2132, @"Proxy timeout");
[self _failWithError:error];
[sself _failWithError:error];
} else if (outStream.streamError != nil) {
[self _failWithError:outStream.streamError];
[sself _failWithError:outStream.streamError];
}
}
[outStream write:bytes maxLength:data.length];
Expand Down
47 changes: 23 additions & 24 deletions SocketRocket/SRWebSocket.m
Expand Up @@ -324,10 +324,9 @@ - (void)open

_selfRetain = self;

if (_urlRequest.timeoutInterval > 0)
{
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, _urlRequest.timeoutInterval * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if (_urlRequest.timeoutInterval > 0) {
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_urlRequest.timeoutInterval * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^{
if (self.readyState == SR_CONNECTING) {
NSError *error = SRErrorWithDomainCodeDescription(NSURLErrorDomain, NSURLErrorTimedOut, @"Timed out connecting to server.");
[self _failWithError:error];
Expand Down Expand Up @@ -435,7 +434,7 @@ - (void)_readHTTPHeader;
_receivedHTTPHeaders = CFHTTPMessageCreateEmpty(NULL, NO);
}

[self _readUntilHeaderCompleteWithCallback:^(SRWebSocket *self, NSData *data) {
[self _readUntilHeaderCompleteWithCallback:^(SRWebSocket *socket, NSData *data) {
CFHTTPMessageAppendBytes(_receivedHTTPHeaders, (const UInt8 *)data.bytes, data.length);

if (CFHTTPMessageIsHeaderComplete(_receivedHTTPHeaders)) {
Expand Down Expand Up @@ -925,17 +924,16 @@ - (void)_handleFrameHeader:(frame_header)frame_header curData:(NSData *)curData;
}
} else {
assert(frame_header.payload_length <= SIZE_T_MAX);
[self _addConsumerWithDataLength:(size_t)frame_header.payload_length callback:^(SRWebSocket *self, NSData *newData) {
[self _addConsumerWithDataLength:(size_t)frame_header.payload_length callback:^(SRWebSocket *sself, NSData *newData) {
if (isControlFrame) {
[self _handleFrameWithData:newData opCode:frame_header.opcode];
[sself _handleFrameWithData:newData opCode:frame_header.opcode];
} else {
if (frame_header.fin) {
[self _handleFrameWithData:self->_currentFrameData opCode:frame_header.opcode];
[sself _handleFrameWithData:sself->_currentFrameData opCode:frame_header.opcode];
} else {
// TODO add assert that opcode is not a control;
[self _readFrameContinue];
[sself _readFrameContinue];
}

}
} readToCurrentFrame:!isControlFrame unmaskBytes:frame_header.masked];
}
Expand Down Expand Up @@ -974,32 +972,32 @@ - (void)_readFrameContinue;
{
assert((_currentFrameCount == 0 && _currentFrameOpcode == 0) || (_currentFrameCount > 0 && _currentFrameOpcode > 0));

[self _addConsumerWithDataLength:2 callback:^(SRWebSocket *self, NSData *data) {
[self _addConsumerWithDataLength:2 callback:^(SRWebSocket *sself, NSData *data) {
__block frame_header header = {0};

const uint8_t *headerBuffer = data.bytes;
assert(data.length >= 2);

if (headerBuffer[0] & SRRsvMask) {
[self _closeWithProtocolError:@"Server used RSV bits"];
[sself _closeWithProtocolError:@"Server used RSV bits"];
return;
}

uint8_t receivedOpcode = (SROpCodeMask & headerBuffer[0]);

BOOL isControlFrame = (receivedOpcode == SROpCodePing || receivedOpcode == SROpCodePong || receivedOpcode == SROpCodeConnectionClose);

if (!isControlFrame && receivedOpcode != 0 && self->_currentFrameCount > 0) {
[self _closeWithProtocolError:@"all data frames after the initial data frame must have opcode 0"];
if (!isControlFrame && receivedOpcode != 0 && sself->_currentFrameCount > 0) {
[sself _closeWithProtocolError:@"all data frames after the initial data frame must have opcode 0"];
return;
}

if (receivedOpcode == 0 && self->_currentFrameCount == 0) {
[self _closeWithProtocolError:@"cannot continue a message"];
if (receivedOpcode == 0 && sself->_currentFrameCount == 0) {
[sself _closeWithProtocolError:@"cannot continue a message"];
return;
}

header.opcode = receivedOpcode == 0 ? self->_currentFrameOpcode : receivedOpcode;
header.opcode = receivedOpcode == 0 ? sself->_currentFrameOpcode : receivedOpcode;

header.fin = !!(SRFinMask & headerBuffer[0]);

Expand All @@ -1010,7 +1008,7 @@ - (void)_readFrameContinue;
headerBuffer = NULL;

if (header.masked) {
[self _closeWithProtocolError:@"Client must receive unmasked data"];
[sself _closeWithProtocolError:@"Client must receive unmasked data"];
return;
}

Expand All @@ -1023,12 +1021,12 @@ - (void)_readFrameContinue;
}

if (extra_bytes_needed == 0) {
[self _handleFrameHeader:header curData:self->_currentFrameData];
[sself _handleFrameHeader:header curData:sself->_currentFrameData];
} else {
[self _addConsumerWithDataLength:extra_bytes_needed callback:^(SRWebSocket *self, NSData *data) {
size_t mapped_size = data.length;
[sself _addConsumerWithDataLength:extra_bytes_needed callback:^(SRWebSocket *eself, NSData *edata) {
size_t mapped_size = edata.length;
#pragma unused (mapped_size)
const void *mapped_buffer = data.bytes;
const void *mapped_buffer = edata.bytes;
size_t offset = 0;

if (header.payload_length == 126) {
Expand All @@ -1046,10 +1044,10 @@ - (void)_readFrameContinue;

if (header.masked) {
assert(mapped_size >= sizeof(_currentReadMaskOffset) + offset);
memcpy(self->_currentReadMaskKey, ((uint8_t *)mapped_buffer) + offset, sizeof(self->_currentReadMaskKey));
memcpy(eself->_currentReadMaskKey, ((uint8_t *)mapped_buffer) + offset, sizeof(eself->_currentReadMaskKey));
}

[self _handleFrameHeader:header curData:self->_currentFrameData];
[eself _handleFrameHeader:header curData:eself->_currentFrameData];
} readToCurrentFrame:NO unmaskBytes:NO];
}
} readToCurrentFrame:NO unmaskBytes:NO];
Expand Down Expand Up @@ -1560,6 +1558,7 @@ - (void)safeHandleEvent:(NSStreamEvent)eventCode stream:(NSStream *)aStream
break;
}

case NSStreamEventNone:
default:
SRDebugLog(@"(default) %@", aStream);
break;
Expand Down
4 changes: 2 additions & 2 deletions Tests/SRAutobahnTests.m
Expand Up @@ -85,8 +85,8 @@ + (SEL)addInstanceMethodForTestCaseNumber:(NSInteger)caseNumber identifier:(NSSt
NSString *selectorName = [NSString stringWithFormat:@"Case #%@", identifier];
SEL selector = NSSelectorFromString(selectorName);

IMP implementation = imp_implementationWithBlock(^(SRAutobahnTests *self) {
[self performTestWithCaseNumber:caseNumber identifier:identifier];
IMP implementation = imp_implementationWithBlock(^(SRAutobahnTests *sself) {
[sself performTestWithCaseNumber:caseNumber identifier:identifier];
});
NSString *typeString = [NSString stringWithFormat:@"%s%s%s", @encode(id), @encode(id), @encode(SEL)];
class_addMethod(self, selector, implementation, typeString.UTF8String);
Expand Down

0 comments on commit eda51ab

Please sign in to comment.