Skip to content

Commit eda51ab

Browse files
committedJul 6, 2016
Fix all new warnings.
1 parent a944d5f commit eda51ab

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed
 

‎SocketRocket/Internal/Proxy/SRProxyConnect.m

+18-18
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,18 @@ - (void)_fetchPAC:(NSURL *)PACurl
231231
[self _openConnection];
232232
return;
233233
}
234-
__weak typeof(self) weakSelf = self;
234+
__weak typeof(self) wself = self;
235235
NSURLRequest *request = [NSURLRequest requestWithURL:PACurl];
236236
NSURLSession *session = [NSURLSession sharedSession];
237-
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
238-
completionHandler:
239-
^(NSData *data, NSURLResponse *response, NSError *error) {
240-
if (!error) {
241-
NSString* script = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
242-
[weakSelf _runPACScript:script];
243-
} else {
244-
[weakSelf _openConnection];
245-
}
246-
247-
}];
248-
[task resume];
237+
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
238+
__strong typeof(wself) sself = wself;
239+
if (!error) {
240+
NSString *script = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
241+
[sself _runPACScript:script];
242+
} else {
243+
[sself _openConnection];
244+
}
245+
}] resume];
249246
}
250247

251248
- (void)_runPACScript:(NSString *)script
@@ -360,6 +357,8 @@ - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode;
360357
[self _processInputStream];
361358
}
362359
} break;
360+
case NSStreamEventHasSpaceAvailable:
361+
case NSStreamEventNone:
363362
default:
364363
SRDebugLog(@"(default) %@", aStream);
365364
break;
@@ -448,13 +447,14 @@ - (void)_proxyHTTPHeadersDidFinish
448447
- (void)_writeData:(NSData *)data
449448
{
450449
const uint8_t * bytes = data.bytes;
451-
__block NSInteger timeout = SRProxyConnectWriteTimeout * 1000000; // wait timeout before giving up
450+
__block NSInteger timeout = (NSInteger)(SRProxyConnectWriteTimeout * 1000000); // wait timeout before giving up
452451
__weak typeof(self) wself = self;
453452
dispatch_async(_writeQueue, ^{
454-
if (!wself) {
453+
__strong typeof(wself) sself = self;
454+
if (!sself) {
455455
return;
456456
}
457-
NSOutputStream *outStream = wself.outputStream;
457+
NSOutputStream *outStream = sself.outputStream;
458458
if (!outStream) {
459459
return;
460460
}
@@ -463,9 +463,9 @@ - (void)_writeData:(NSData *)data
463463
timeout -= 100;
464464
if (timeout < 0) {
465465
NSError *error = SRHTTPErrorWithCodeDescription(408, 2132, @"Proxy timeout");
466-
[self _failWithError:error];
466+
[sself _failWithError:error];
467467
} else if (outStream.streamError != nil) {
468-
[self _failWithError:outStream.streamError];
468+
[sself _failWithError:outStream.streamError];
469469
}
470470
}
471471
[outStream write:bytes maxLength:data.length];

‎SocketRocket/SRWebSocket.m

+23-24
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,9 @@ - (void)open
324324

325325
_selfRetain = self;
326326

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

438-
[self _readUntilHeaderCompleteWithCallback:^(SRWebSocket *self, NSData *data) {
437+
[self _readUntilHeaderCompleteWithCallback:^(SRWebSocket *socket, NSData *data) {
439438
CFHTTPMessageAppendBytes(_receivedHTTPHeaders, (const UInt8 *)data.bytes, data.length);
440439

441440
if (CFHTTPMessageIsHeaderComplete(_receivedHTTPHeaders)) {
@@ -925,17 +924,16 @@ - (void)_handleFrameHeader:(frame_header)frame_header curData:(NSData *)curData;
925924
}
926925
} else {
927926
assert(frame_header.payload_length <= SIZE_T_MAX);
928-
[self _addConsumerWithDataLength:(size_t)frame_header.payload_length callback:^(SRWebSocket *self, NSData *newData) {
927+
[self _addConsumerWithDataLength:(size_t)frame_header.payload_length callback:^(SRWebSocket *sself, NSData *newData) {
929928
if (isControlFrame) {
930-
[self _handleFrameWithData:newData opCode:frame_header.opcode];
929+
[sself _handleFrameWithData:newData opCode:frame_header.opcode];
931930
} else {
932931
if (frame_header.fin) {
933-
[self _handleFrameWithData:self->_currentFrameData opCode:frame_header.opcode];
932+
[sself _handleFrameWithData:sself->_currentFrameData opCode:frame_header.opcode];
934933
} else {
935934
// TODO add assert that opcode is not a control;
936-
[self _readFrameContinue];
935+
[sself _readFrameContinue];
937936
}
938-
939937
}
940938
} readToCurrentFrame:!isControlFrame unmaskBytes:frame_header.masked];
941939
}
@@ -974,32 +972,32 @@ - (void)_readFrameContinue;
974972
{
975973
assert((_currentFrameCount == 0 && _currentFrameOpcode == 0) || (_currentFrameCount > 0 && _currentFrameOpcode > 0));
976974

977-
[self _addConsumerWithDataLength:2 callback:^(SRWebSocket *self, NSData *data) {
975+
[self _addConsumerWithDataLength:2 callback:^(SRWebSocket *sself, NSData *data) {
978976
__block frame_header header = {0};
979977

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

983981
if (headerBuffer[0] & SRRsvMask) {
984-
[self _closeWithProtocolError:@"Server used RSV bits"];
982+
[sself _closeWithProtocolError:@"Server used RSV bits"];
985983
return;
986984
}
987985

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

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

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

997-
if (receivedOpcode == 0 && self->_currentFrameCount == 0) {
998-
[self _closeWithProtocolError:@"cannot continue a message"];
995+
if (receivedOpcode == 0 && sself->_currentFrameCount == 0) {
996+
[sself _closeWithProtocolError:@"cannot continue a message"];
999997
return;
1000998
}
1001999

1002-
header.opcode = receivedOpcode == 0 ? self->_currentFrameOpcode : receivedOpcode;
1000+
header.opcode = receivedOpcode == 0 ? sself->_currentFrameOpcode : receivedOpcode;
10031001

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

@@ -1010,7 +1008,7 @@ - (void)_readFrameContinue;
10101008
headerBuffer = NULL;
10111009

10121010
if (header.masked) {
1013-
[self _closeWithProtocolError:@"Client must receive unmasked data"];
1011+
[sself _closeWithProtocolError:@"Client must receive unmasked data"];
10141012
return;
10151013
}
10161014

@@ -1023,12 +1021,12 @@ - (void)_readFrameContinue;
10231021
}
10241022

10251023
if (extra_bytes_needed == 0) {
1026-
[self _handleFrameHeader:header curData:self->_currentFrameData];
1024+
[sself _handleFrameHeader:header curData:sself->_currentFrameData];
10271025
} else {
1028-
[self _addConsumerWithDataLength:extra_bytes_needed callback:^(SRWebSocket *self, NSData *data) {
1029-
size_t mapped_size = data.length;
1026+
[sself _addConsumerWithDataLength:extra_bytes_needed callback:^(SRWebSocket *eself, NSData *edata) {
1027+
size_t mapped_size = edata.length;
10301028
#pragma unused (mapped_size)
1031-
const void *mapped_buffer = data.bytes;
1029+
const void *mapped_buffer = edata.bytes;
10321030
size_t offset = 0;
10331031

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

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

1052-
[self _handleFrameHeader:header curData:self->_currentFrameData];
1050+
[eself _handleFrameHeader:header curData:eself->_currentFrameData];
10531051
} readToCurrentFrame:NO unmaskBytes:NO];
10541052
}
10551053
} readToCurrentFrame:NO unmaskBytes:NO];
@@ -1560,6 +1558,7 @@ - (void)safeHandleEvent:(NSStreamEvent)eventCode stream:(NSStream *)aStream
15601558
break;
15611559
}
15621560

1561+
case NSStreamEventNone:
15631562
default:
15641563
SRDebugLog(@"(default) %@", aStream);
15651564
break;

‎Tests/SRAutobahnTests.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ + (SEL)addInstanceMethodForTestCaseNumber:(NSInteger)caseNumber identifier:(NSSt
8585
NSString *selectorName = [NSString stringWithFormat:@"Case #%@", identifier];
8686
SEL selector = NSSelectorFromString(selectorName);
8787

88-
IMP implementation = imp_implementationWithBlock(^(SRAutobahnTests *self) {
89-
[self performTestWithCaseNumber:caseNumber identifier:identifier];
88+
IMP implementation = imp_implementationWithBlock(^(SRAutobahnTests *sself) {
89+
[sself performTestWithCaseNumber:caseNumber identifier:identifier];
9090
});
9191
NSString *typeString = [NSString stringWithFormat:@"%s%s%s", @encode(id), @encode(id), @encode(SEL)];
9292
class_addMethod(self, selector, implementation, typeString.UTF8String);

0 commit comments

Comments
 (0)
Please sign in to comment.