Explorar o código

Merge pull request #323 from isleofcode/master

Respect timeouts set on `NSURLRequest`s passed at init fix #70
Dan Federman %!s(int64=9) %!d(string=hai) anos
pai
achega
192e7b769b
Modificáronse 1 ficheiros con 10 adicións e 1 borrados
  1. 10 1
      SocketRocket/SRWebSocket.m

+ 10 - 1
SocketRocket/SRWebSocket.m

@@ -389,7 +389,16 @@ static __strong NSData *CRLFCRLF;
     NSAssert(_readyState == SR_CONNECTING, @"Cannot call -(void)open on SRWebSocket more than once");
 
     _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 (self.readyState == SR_CONNECTING)
+                [self _failWithError:[NSError errorWithDomain:@"com.squareup.SocketRocket" code:504 userInfo:@{NSLocalizedDescriptionKey: @"Timeout Connecting to Server"}]];
+        });
+    }
+
     [self openConnection];
 }