Bladeren bron

Fix all new warnings.

Nikita Lutsenko 9 jaren geleden
bovenliggende
commit
eda51aba1b
3 gewijzigde bestanden met toevoegingen van 43 en 44 verwijderingen
  1. 18 18
      SocketRocket/Internal/Proxy/SRProxyConnect.m
  2. 23 24
      SocketRocket/SRWebSocket.m
  3. 2 2
      Tests/SRAutobahnTests.m

+ 18 - 18
SocketRocket/Internal/Proxy/SRProxyConnect.m

@@ -231,21 +231,18 @@
         [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
@@ -360,6 +357,8 @@
                 [self _processInputStream];
             }
         } break;
+        case NSStreamEventHasSpaceAvailable:
+        case NSStreamEventNone:
         default:
             SRDebugLog(@"(default)  %@", aStream);
             break;
@@ -448,13 +447,14 @@ static NSTimeInterval const SRProxyConnectWriteTimeout = 5.0;
 - (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;
         }
@@ -463,9 +463,9 @@ static NSTimeInterval const SRProxyConnectWriteTimeout = 5.0;
             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];

+ 23 - 24
SocketRocket/SRWebSocket.m

@@ -324,10 +324,9 @@ NSString *const SRHTTPResponseErrorKey = @"HTTPResponseStatusCode";
 
     _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];
@@ -435,7 +434,7 @@ NSString *const SRHTTPResponseErrorKey = @"HTTPResponseStatusCode";
         _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)) {
@@ -925,17 +924,16 @@ static inline BOOL closeCodeIsValid(int closeCode) {
         }
     } 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];
     }
@@ -974,14 +972,14 @@ static const uint8_t SRPayloadLenMask   = 0x7F;
 {
     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;
         }
 
@@ -989,17 +987,17 @@ static const uint8_t SRPayloadLenMask   = 0x7F;
 
         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]);
 
@@ -1010,7 +1008,7 @@ static const uint8_t SRPayloadLenMask   = 0x7F;
         headerBuffer = NULL;
 
         if (header.masked) {
-            [self _closeWithProtocolError:@"Client must receive unmasked data"];
+            [sself _closeWithProtocolError:@"Client must receive unmasked data"];
             return;
         }
 
@@ -1023,12 +1021,12 @@ static const uint8_t SRPayloadLenMask   = 0x7F;
         }
 
         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) {
@@ -1046,10 +1044,10 @@ static const uint8_t SRPayloadLenMask   = 0x7F;
 
                 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];
@@ -1560,6 +1558,7 @@ static const size_t SRFrameHeaderOverhead = 32;
             break;
         }
 
+        case NSStreamEventNone:
         default:
             SRDebugLog(@"(default)  %@", aStream);
             break;

+ 2 - 2
Tests/SRAutobahnTests.m

@@ -85,8 +85,8 @@
     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);