@@ -2498,12 +2498,12 @@ - (void)didConnect:(int)aConnectIndex
2498
2498
NSString *host = [self connectedHost ];
2499
2499
uint16_t port = [self connectedPort ];
2500
2500
2501
- if (delegateQueue && [delegate respondsToSelector: @selector (socket:didConnectToHost:port: )])
2501
+ __strong id theDelegate = delegate;
2502
+
2503
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socket:didConnectToHost:port: )])
2502
2504
{
2503
2505
SetupStreamsPart1 ();
2504
2506
2505
- __strong id theDelegate = delegate;
2506
-
2507
2507
dispatch_async (delegateQueue, ^{ @autoreleasepool {
2508
2508
2509
2509
[theDelegate socket: self didConnectToHost: host port: port];
@@ -2774,10 +2774,10 @@ - (void)closeWithError:(NSError *)error
2774
2774
2775
2775
if (shouldCallDelegate)
2776
2776
{
2777
- if (delegateQueue && [delegate respondsToSelector: @selector (socketDidDisconnect:withError: )])
2777
+ __strong id theDelegate = delegate;
2778
+
2779
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socketDidDisconnect:withError: )])
2778
2780
{
2779
- __strong id theDelegate = delegate;
2780
-
2781
2781
dispatch_async (delegateQueue, ^{ @autoreleasepool {
2782
2782
2783
2783
[theDelegate socketDidDisconnect: self withError: error];
@@ -4832,10 +4832,11 @@ - (void)doReadData
4832
4832
else if (totalBytesReadForCurrentRead > 0 )
4833
4833
{
4834
4834
// We're not done read type #2 or #3 yet, but we have read in some bytes
4835
+
4836
+ __strong id theDelegate = delegate;
4835
4837
4836
- if (delegateQueue && [delegate respondsToSelector: @selector (socket:didReadPartialDataOfLength:tag: )])
4838
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socket:didReadPartialDataOfLength:tag: )])
4837
4839
{
4838
- __strong id theDelegate = delegate;
4839
4840
long theReadTag = currentRead->tag ;
4840
4841
4841
4842
dispatch_async (delegateQueue, ^{ @autoreleasepool {
@@ -4948,10 +4949,10 @@ - (void)doReadEOF
4948
4949
4949
4950
// Notify the delegate that we're going half-duplex
4950
4951
4951
- if (delegateQueue && [delegate respondsToSelector: @selector (socketDidCloseReadStream: )])
4952
+ __strong id theDelegate = delegate;
4953
+
4954
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socketDidCloseReadStream: )])
4952
4955
{
4953
- __strong id theDelegate = delegate;
4954
-
4955
4956
dispatch_async (delegateQueue, ^{ @autoreleasepool {
4956
4957
4957
4958
[theDelegate socketDidCloseReadStream: self ];
@@ -5044,9 +5045,10 @@ - (void)completeCurrentRead
5044
5045
result = [NSData dataWithBytesNoCopy: buffer length: currentRead->bytesDone freeWhenDone: NO ];
5045
5046
}
5046
5047
5047
- if (delegateQueue && [delegate respondsToSelector: @selector (socket:didReadData:withTag: )])
5048
+ __strong id theDelegate = delegate;
5049
+
5050
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socket:didReadData:withTag: )])
5048
5051
{
5049
- __strong id theDelegate = delegate;
5050
5052
GCDAsyncReadPacket *theRead = currentRead; // Ensure currentRead retained since result may not own buffer
5051
5053
5052
5054
dispatch_async (delegateQueue, ^{ @autoreleasepool {
@@ -5104,9 +5106,10 @@ - (void)doReadTimeout
5104
5106
5105
5107
flags |= kReadsPaused ;
5106
5108
5107
- if (delegateQueue && [delegate respondsToSelector: @selector (socket:shouldTimeoutReadWithTag:elapsed:bytesDone: )])
5109
+ __strong id theDelegate = delegate;
5110
+
5111
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socket:shouldTimeoutReadWithTag:elapsed:bytesDone: )])
5108
5112
{
5109
- __strong id theDelegate = delegate;
5110
5113
GCDAsyncReadPacket *theRead = currentRead;
5111
5114
5112
5115
dispatch_async (delegateQueue, ^{ @autoreleasepool {
@@ -5645,9 +5648,10 @@ - (void)doWriteData
5645
5648
{
5646
5649
// We're not done with the entire write, but we have written some bytes
5647
5650
5648
- if (delegateQueue && [delegate respondsToSelector: @selector (socket:didWritePartialDataOfLength:tag: )])
5651
+ __strong id theDelegate = delegate;
5652
+
5653
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socket:didWritePartialDataOfLength:tag: )])
5649
5654
{
5650
- __strong id theDelegate = delegate;
5651
5655
long theWriteTag = currentWrite->tag ;
5652
5656
5653
5657
dispatch_async (delegateQueue, ^{ @autoreleasepool {
@@ -5674,10 +5678,11 @@ - (void)completeCurrentWrite
5674
5678
5675
5679
NSAssert (currentWrite, @" Trying to complete current write when there is no current write." );
5676
5680
5681
+
5682
+ __strong id theDelegate = delegate;
5677
5683
5678
- if (delegateQueue && [delegate respondsToSelector: @selector (socket:didWriteDataWithTag: )])
5684
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socket:didWriteDataWithTag: )])
5679
5685
{
5680
- __strong id theDelegate = delegate;
5681
5686
long theWriteTag = currentWrite->tag ;
5682
5687
5683
5688
dispatch_async (delegateQueue, ^{ @autoreleasepool {
@@ -5735,9 +5740,10 @@ - (void)doWriteTimeout
5735
5740
5736
5741
flags |= kWritesPaused ;
5737
5742
5738
- if (delegateQueue && [delegate respondsToSelector: @selector (socket:shouldTimeoutWriteWithTag:elapsed:bytesDone: )])
5743
+ __strong id theDelegate = delegate;
5744
+
5745
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socket:shouldTimeoutWriteWithTag:elapsed:bytesDone: )])
5739
5746
{
5740
- __strong id theDelegate = delegate;
5741
5747
GCDAsyncWritePacket *theWrite = currentWrite;
5742
5748
5743
5749
dispatch_async (delegateQueue, ^{ @autoreleasepool {
@@ -6514,10 +6520,10 @@ - (void)ssl_continueSSLHandshake
6514
6520
6515
6521
flags |= kSocketSecure ;
6516
6522
6517
- if (delegateQueue && [delegate respondsToSelector: @selector (socketDidSecure: )])
6523
+ __strong id theDelegate = delegate;
6524
+
6525
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socketDidSecure: )])
6518
6526
{
6519
- __strong id theDelegate = delegate;
6520
-
6521
6527
dispatch_async (delegateQueue, ^{ @autoreleasepool {
6522
6528
6523
6529
[theDelegate socketDidSecure: self ];
@@ -6563,10 +6569,10 @@ - (void)cf_finishSSLHandshake
6563
6569
6564
6570
flags |= kSocketSecure ;
6565
6571
6566
- if (delegateQueue && [delegate respondsToSelector: @selector (socketDidSecure: )])
6572
+ __strong id theDelegate = delegate;
6573
+
6574
+ if (delegateQueue && [theDelegate respondsToSelector: @selector (socketDidSecure: )])
6567
6575
{
6568
- __strong id theDelegate = delegate;
6569
-
6570
6576
dispatch_async (delegateQueue, ^{ @autoreleasepool {
6571
6577
6572
6578
[theDelegate socketDidSecure: self ];
0 commit comments