Selaa lähdekoodia

Cleanup proxy connect reference when socket is opened asynchronously.

Nikita Lutsenko 9 vuotta sitten
vanhempi
commit
9c2201f099
1 muutettua tiedostoa jossa 5 lisäystä ja 2 poistoa
  1. 5 2
      SocketRocket/SRWebSocket.m

+ 5 - 2
SocketRocket/SRWebSocket.m

@@ -326,8 +326,6 @@ NSString *const SRHTTPResponseErrorKey = @"HTTPResponseStatusCode";
 
 - (void)_connectionDoneWithError:(NSError *)error readStream:(NSInputStream *)readStream writeStream:(NSOutputStream *)writeStream
 {
-    _proxyConnect = nil; // Job's done! This is not longer required.
-
     if (error != nil) {
         [self _failWithError:error];
     } else {
@@ -350,6 +348,11 @@ NSString *const SRHTTPResponseErrorKey = @"HTTPResponseStatusCode";
             });
         }
     }
+    // Schedule to run on a work queue, to make sure we don't run this inline and deallocate `self` inside `SRProxyConnect`.
+    // TODO: (nlutsenko) Find a better structure for this, maybe Bolts Tasks?
+    dispatch_async(_workQueue, ^{
+        _proxyConnect = nil;
+    });
 }
 
 - (BOOL)_checkHandshake:(CFHTTPMessageRef)httpMessage;