浏览代码

Optimize input queue processing in SRProxyConnect.

Nikita Lutsenko 9 年之前
父节点
当前提交
88cdc0b586
共有 1 个文件被更改,包括 10 次插入3 次删除
  1. 10 3
      SocketRocket/Internal/Proxy/SRProxyConnect.m

+ 10 - 3
SocketRocket/Internal/Proxy/SRProxyConnect.m

@@ -407,13 +407,17 @@
 - (void)_dequeueInput
 {
     while (_inputQueue.count > 0) {
-        NSData *data = _inputQueue[0];
-        [self _proxyProcessHTTPResponseWithData:data];
+        NSData *data = _inputQueue.firstObject;
         [_inputQueue removeObjectAtIndex:0];
+
+        // No need to process any data further, we got the full header data.
+        if ([self _proxyProcessHTTPResponseWithData:data]) {
+            break;
+        }
     }
 }
 //handle checking the proxy  connection status
-- (void)_proxyProcessHTTPResponseWithData:(NSData *)data
+- (BOOL)_proxyProcessHTTPResponseWithData:(NSData *)data
 {
     if (_receivedHTTPHeaders == NULL) {
         _receivedHTTPHeaders = CFHTTPMessageCreateEmpty(NULL, NO);
@@ -423,7 +427,10 @@
     if (CFHTTPMessageIsHeaderComplete(_receivedHTTPHeaders)) {
         SRDebugLog(@"Finished reading headers %@", CFBridgingRelease(CFHTTPMessageCopyAllHeaderFields(_receivedHTTPHeaders)));
         [self _proxyHTTPHeadersDidFinish];
+        return YES;
     }
+
+    return NO;
 }
 
 - (void)_proxyHTTPHeadersDidFinish