Skip to content

Commit 42fa5c9

Browse files
committed
GCDAsyncSocket: fixing -Wreceiver-is-weak warnings.
Fixes robbiehanson#206
1 parent f07ee11 commit 42fa5c9

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

GCD/GCDAsyncSocket.m

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,12 +2498,12 @@ - (void)didConnect:(int)aConnectIndex
24982498
NSString *host = [self connectedHost];
24992499
uint16_t port = [self connectedPort];
25002500

2501-
if (delegateQueue && [delegate respondsToSelector:@selector(socket:didConnectToHost:port:)])
2501+
__strong id theDelegate = delegate;
2502+
2503+
if (delegateQueue && [theDelegate respondsToSelector:@selector(socket:didConnectToHost:port:)])
25022504
{
25032505
SetupStreamsPart1();
25042506

2505-
__strong id theDelegate = delegate;
2506-
25072507
dispatch_async(delegateQueue, ^{ @autoreleasepool {
25082508

25092509
[theDelegate socket:self didConnectToHost:host port:port];
@@ -2774,10 +2774,10 @@ - (void)closeWithError:(NSError *)error
27742774

27752775
if (shouldCallDelegate)
27762776
{
2777-
if (delegateQueue && [delegate respondsToSelector: @selector(socketDidDisconnect:withError:)])
2777+
__strong id theDelegate = delegate;
2778+
2779+
if (delegateQueue && [theDelegate respondsToSelector: @selector(socketDidDisconnect:withError:)])
27782780
{
2779-
__strong id theDelegate = delegate;
2780-
27812781
dispatch_async(delegateQueue, ^{ @autoreleasepool {
27822782

27832783
[theDelegate socketDidDisconnect:self withError:error];
@@ -4832,10 +4832,11 @@ - (void)doReadData
48324832
else if (totalBytesReadForCurrentRead > 0)
48334833
{
48344834
// We're not done read type #2 or #3 yet, but we have read in some bytes
4835+
4836+
__strong id theDelegate = delegate;
48354837

4836-
if (delegateQueue && [delegate respondsToSelector:@selector(socket:didReadPartialDataOfLength:tag:)])
4838+
if (delegateQueue && [theDelegate respondsToSelector:@selector(socket:didReadPartialDataOfLength:tag:)])
48374839
{
4838-
__strong id theDelegate = delegate;
48394840
long theReadTag = currentRead->tag;
48404841

48414842
dispatch_async(delegateQueue, ^{ @autoreleasepool {
@@ -4948,10 +4949,10 @@ - (void)doReadEOF
49484949

49494950
// Notify the delegate that we're going half-duplex
49504951

4951-
if (delegateQueue && [delegate respondsToSelector:@selector(socketDidCloseReadStream:)])
4952+
__strong id theDelegate = delegate;
4953+
4954+
if (delegateQueue && [theDelegate respondsToSelector:@selector(socketDidCloseReadStream:)])
49524955
{
4953-
__strong id theDelegate = delegate;
4954-
49554956
dispatch_async(delegateQueue, ^{ @autoreleasepool {
49564957

49574958
[theDelegate socketDidCloseReadStream:self];
@@ -5044,9 +5045,10 @@ - (void)completeCurrentRead
50445045
result = [NSData dataWithBytesNoCopy:buffer length:currentRead->bytesDone freeWhenDone:NO];
50455046
}
50465047

5047-
if (delegateQueue && [delegate respondsToSelector:@selector(socket:didReadData:withTag:)])
5048+
__strong id theDelegate = delegate;
5049+
5050+
if (delegateQueue && [theDelegate respondsToSelector:@selector(socket:didReadData:withTag:)])
50485051
{
5049-
__strong id theDelegate = delegate;
50505052
GCDAsyncReadPacket *theRead = currentRead; // Ensure currentRead retained since result may not own buffer
50515053

50525054
dispatch_async(delegateQueue, ^{ @autoreleasepool {
@@ -5104,9 +5106,10 @@ - (void)doReadTimeout
51045106

51055107
flags |= kReadsPaused;
51065108

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:)])
51085112
{
5109-
__strong id theDelegate = delegate;
51105113
GCDAsyncReadPacket *theRead = currentRead;
51115114

51125115
dispatch_async(delegateQueue, ^{ @autoreleasepool {
@@ -5645,9 +5648,10 @@ - (void)doWriteData
56455648
{
56465649
// We're not done with the entire write, but we have written some bytes
56475650

5648-
if (delegateQueue && [delegate respondsToSelector:@selector(socket:didWritePartialDataOfLength:tag:)])
5651+
__strong id theDelegate = delegate;
5652+
5653+
if (delegateQueue && [theDelegate respondsToSelector:@selector(socket:didWritePartialDataOfLength:tag:)])
56495654
{
5650-
__strong id theDelegate = delegate;
56515655
long theWriteTag = currentWrite->tag;
56525656

56535657
dispatch_async(delegateQueue, ^{ @autoreleasepool {
@@ -5674,10 +5678,11 @@ - (void)completeCurrentWrite
56745678

56755679
NSAssert(currentWrite, @"Trying to complete current write when there is no current write.");
56765680

5681+
5682+
__strong id theDelegate = delegate;
56775683

5678-
if (delegateQueue && [delegate respondsToSelector:@selector(socket:didWriteDataWithTag:)])
5684+
if (delegateQueue && [theDelegate respondsToSelector:@selector(socket:didWriteDataWithTag:)])
56795685
{
5680-
__strong id theDelegate = delegate;
56815686
long theWriteTag = currentWrite->tag;
56825687

56835688
dispatch_async(delegateQueue, ^{ @autoreleasepool {
@@ -5735,9 +5740,10 @@ - (void)doWriteTimeout
57355740

57365741
flags |= kWritesPaused;
57375742

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:)])
57395746
{
5740-
__strong id theDelegate = delegate;
57415747
GCDAsyncWritePacket *theWrite = currentWrite;
57425748

57435749
dispatch_async(delegateQueue, ^{ @autoreleasepool {
@@ -6514,10 +6520,10 @@ - (void)ssl_continueSSLHandshake
65146520

65156521
flags |= kSocketSecure;
65166522

6517-
if (delegateQueue && [delegate respondsToSelector:@selector(socketDidSecure:)])
6523+
__strong id theDelegate = delegate;
6524+
6525+
if (delegateQueue && [theDelegate respondsToSelector:@selector(socketDidSecure:)])
65186526
{
6519-
__strong id theDelegate = delegate;
6520-
65216527
dispatch_async(delegateQueue, ^{ @autoreleasepool {
65226528

65236529
[theDelegate socketDidSecure:self];
@@ -6563,10 +6569,10 @@ - (void)cf_finishSSLHandshake
65636569

65646570
flags |= kSocketSecure;
65656571

6566-
if (delegateQueue && [delegate respondsToSelector:@selector(socketDidSecure:)])
6572+
__strong id theDelegate = delegate;
6573+
6574+
if (delegateQueue && [theDelegate respondsToSelector:@selector(socketDidSecure:)])
65676575
{
6568-
__strong id theDelegate = delegate;
6569-
65706576
dispatch_async(delegateQueue, ^{ @autoreleasepool {
65716577

65726578
[theDelegate socketDidSecure:self];

0 commit comments

Comments
 (0)