Skip to content

Commit 6fbb802

Browse files
Merge pull request robbiehanson#336 from pcbeard/Delegate2
Change all GCD UDP delegate types to id <GCDAsyncUdpSocketDelegate>
2 parents 1685d1c + c0b6023 commit 6fbb802

File tree

6 files changed

+77
-77
lines changed

6 files changed

+77
-77
lines changed

Examples/GCD/UdpEchoClient/Desktop/UdpEchoClient/AppDelegate.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#import <Cocoa/Cocoa.h>
2+
#import "GCDAsyncUdpSocket.h"
23

3-
@class GCDAsyncUdpSocket;
4-
5-
6-
@interface AppDelegate : NSObject <NSApplicationDelegate>
4+
@interface AppDelegate : NSObject <NSApplicationDelegate, GCDAsyncUdpSocketDelegate>
75
{
86
long tag;
97
GCDAsyncUdpSocket *udpSocket;

Examples/GCD/UdpEchoClient/Mobile/UdpEchoClient/ViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#import <UIKit/UIKit.h>
2+
#import "GCDAsyncUdpSocket.h"
23

3-
4-
@interface ViewController : UIViewController
4+
@interface ViewController : UIViewController <GCDAsyncUdpSocketDelegate>
55
{
66
IBOutlet UITextField *addrField;
77
IBOutlet UITextField *portField;

Examples/GCD/UdpEchoServer/Desktop/UdpEchoServer/AppDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#import "GCDAsyncUdpSocket.h"
33

44

5-
@interface AppDelegate : NSObject <NSApplicationDelegate>
5+
@interface AppDelegate : NSObject <NSApplicationDelegate, GCDAsyncUdpSocketDelegate>
66
{
77
GCDAsyncUdpSocket *udpSocket;
88
BOOL isRunning;

Examples/GCD/UdpEchoServer/Mobile/UdpEchoServer/ViewController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#import <UIKit/UIKit.h>
2+
#import "GCDAsyncUdpSocket.h"
23

3-
4-
@interface ViewController : UIViewController
4+
@interface ViewController : UIViewController <GCDAsyncUdpSocketDelegate>
55
{
66
IBOutlet UITextField *portField;
77
IBOutlet UIButton *startStopButton;

Source/GCD/GCDAsyncUdpSocket.h

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,59 @@ typedef NS_ENUM(NSInteger, GCDAsyncUdpSocketError) {
2828
GCDAsyncUdpSocketOtherError, // Description provided in userInfo
2929
};
3030

31+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32+
#pragma mark -
33+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34+
35+
@class GCDAsyncUdpSocket;
36+
37+
@protocol GCDAsyncUdpSocketDelegate
38+
@optional
39+
40+
/**
41+
* By design, UDP is a connectionless protocol, and connecting is not needed.
42+
* However, you may optionally choose to connect to a particular host for reasons
43+
* outlined in the documentation for the various connect methods listed above.
44+
*
45+
* This method is called if one of the connect methods are invoked, and the connection is successful.
46+
**/
47+
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didConnectToAddress:(NSData *)address;
48+
49+
/**
50+
* By design, UDP is a connectionless protocol, and connecting is not needed.
51+
* However, you may optionally choose to connect to a particular host for reasons
52+
* outlined in the documentation for the various connect methods listed above.
53+
*
54+
* This method is called if one of the connect methods are invoked, and the connection fails.
55+
* This may happen, for example, if a domain name is given for the host and the domain name is unable to be resolved.
56+
**/
57+
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didNotConnect:(NSError *)error;
58+
59+
/**
60+
* Called when the datagram with the given tag has been sent.
61+
**/
62+
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didSendDataWithTag:(long)tag;
63+
64+
/**
65+
* Called if an error occurs while trying to send a datagram.
66+
* This could be due to a timeout, or something more serious such as the data being too large to fit in a sigle packet.
67+
**/
68+
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didNotSendDataWithTag:(long)tag dueToError:(NSError *)error;
69+
70+
/**
71+
* Called when the socket has received the requested datagram.
72+
**/
73+
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data
74+
fromAddress:(NSData *)address
75+
withFilterContext:(id)filterContext;
76+
77+
/**
78+
* Called when the socket is closed.
79+
**/
80+
- (void)udpSocketDidClose:(GCDAsyncUdpSocket *)sock withError:(NSError *)error;
81+
82+
@end
83+
3184
/**
3285
* You may optionally set a receive filter for the socket.
3386
* A filter can provide several useful features:
@@ -126,22 +179,22 @@ typedef BOOL (^GCDAsyncUdpSocketSendFilterBlock)(NSData *data, NSData *address,
126179
**/
127180
- (id)init;
128181
- (id)initWithSocketQueue:(dispatch_queue_t)sq;
129-
- (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq;
130-
- (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq socketQueue:(dispatch_queue_t)sq;
182+
- (id)initWithDelegate:(id <GCDAsyncUdpSocketDelegate>)aDelegate delegateQueue:(dispatch_queue_t)dq;
183+
- (id)initWithDelegate:(id <GCDAsyncUdpSocketDelegate>)aDelegate delegateQueue:(dispatch_queue_t)dq socketQueue:(dispatch_queue_t)sq;
131184

132185
#pragma mark Configuration
133186

134-
- (id)delegate;
135-
- (void)setDelegate:(id)delegate;
136-
- (void)synchronouslySetDelegate:(id)delegate;
187+
- (id <GCDAsyncUdpSocketDelegate>)delegate;
188+
- (void)setDelegate:(id <GCDAsyncUdpSocketDelegate>)delegate;
189+
- (void)synchronouslySetDelegate:(id <GCDAsyncUdpSocketDelegate>)delegate;
137190

138191
- (dispatch_queue_t)delegateQueue;
139192
- (void)setDelegateQueue:(dispatch_queue_t)delegateQueue;
140193
- (void)synchronouslySetDelegateQueue:(dispatch_queue_t)delegateQueue;
141194

142-
- (void)getDelegate:(id *)delegatePtr delegateQueue:(dispatch_queue_t *)delegateQueuePtr;
143-
- (void)setDelegate:(id)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
144-
- (void)synchronouslySetDelegate:(id)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
195+
- (void)getDelegate:(id <GCDAsyncUdpSocketDelegate>*)delegatePtr delegateQueue:(dispatch_queue_t *)delegateQueuePtr;
196+
- (void)setDelegate:(id <GCDAsyncUdpSocketDelegate>)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
197+
- (void)synchronouslySetDelegate:(id <GCDAsyncUdpSocketDelegate>)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
145198

146199
/**
147200
* By default, both IPv4 and IPv6 are enabled.
@@ -941,54 +994,3 @@ typedef BOOL (^GCDAsyncUdpSocketSendFilterBlock)(NSData *data, NSData *address,
941994

942995
@end
943996

944-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
945-
#pragma mark -
946-
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
947-
948-
@protocol GCDAsyncUdpSocketDelegate
949-
@optional
950-
951-
/**
952-
* By design, UDP is a connectionless protocol, and connecting is not needed.
953-
* However, you may optionally choose to connect to a particular host for reasons
954-
* outlined in the documentation for the various connect methods listed above.
955-
*
956-
* This method is called if one of the connect methods are invoked, and the connection is successful.
957-
**/
958-
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didConnectToAddress:(NSData *)address;
959-
960-
/**
961-
* By design, UDP is a connectionless protocol, and connecting is not needed.
962-
* However, you may optionally choose to connect to a particular host for reasons
963-
* outlined in the documentation for the various connect methods listed above.
964-
*
965-
* This method is called if one of the connect methods are invoked, and the connection fails.
966-
* This may happen, for example, if a domain name is given for the host and the domain name is unable to be resolved.
967-
**/
968-
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didNotConnect:(NSError *)error;
969-
970-
/**
971-
* Called when the datagram with the given tag has been sent.
972-
**/
973-
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didSendDataWithTag:(long)tag;
974-
975-
/**
976-
* Called if an error occurs while trying to send a datagram.
977-
* This could be due to a timeout, or something more serious such as the data being too large to fit in a sigle packet.
978-
**/
979-
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didNotSendDataWithTag:(long)tag dueToError:(NSError *)error;
980-
981-
/**
982-
* Called when the socket has received the requested datagram.
983-
**/
984-
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data
985-
fromAddress:(NSData *)address
986-
withFilterContext:(id)filterContext;
987-
988-
/**
989-
* Called when the socket is closed.
990-
**/
991-
- (void)udpSocketDidClose:(GCDAsyncUdpSocket *)sock withError:(NSError *)error;
992-
993-
@end
994-

Source/GCD/GCDAsyncUdpSocket.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,14 @@ - (id)initWithSocketQueue:(dispatch_queue_t)sq
350350
return [self initWithDelegate:nil delegateQueue:NULL socketQueue:sq];
351351
}
352352

353-
- (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq
353+
- (id)initWithDelegate:(id <GCDAsyncUdpSocketDelegate>)aDelegate delegateQueue:(dispatch_queue_t)dq
354354
{
355355
LogTrace();
356356

357357
return [self initWithDelegate:aDelegate delegateQueue:dq socketQueue:NULL];
358358
}
359359

360-
- (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq socketQueue:(dispatch_queue_t)sq
360+
- (id)initWithDelegate:(id <GCDAsyncUdpSocketDelegate>)aDelegate delegateQueue:(dispatch_queue_t)dq socketQueue:(dispatch_queue_t)sq
361361
{
362362
LogTrace();
363363

@@ -488,7 +488,7 @@ - (id)delegate
488488
}
489489
}
490490

491-
- (void)setDelegate:(id)newDelegate synchronously:(BOOL)synchronously
491+
- (void)setDelegate:(id <GCDAsyncUdpSocketDelegate>)newDelegate synchronously:(BOOL)synchronously
492492
{
493493
dispatch_block_t block = ^{
494494
delegate = newDelegate;
@@ -505,12 +505,12 @@ - (void)setDelegate:(id)newDelegate synchronously:(BOOL)synchronously
505505
}
506506
}
507507

508-
- (void)setDelegate:(id)newDelegate
508+
- (void)setDelegate:(id <GCDAsyncUdpSocketDelegate>)newDelegate
509509
{
510510
[self setDelegate:newDelegate synchronously:NO];
511511
}
512512

513-
- (void)synchronouslySetDelegate:(id)newDelegate
513+
- (void)synchronouslySetDelegate:(id <GCDAsyncUdpSocketDelegate>)newDelegate
514514
{
515515
[self setDelegate:newDelegate synchronously:YES];
516516
}
@@ -566,7 +566,7 @@ - (void)synchronouslySetDelegateQueue:(dispatch_queue_t)newDelegateQueue
566566
[self setDelegateQueue:newDelegateQueue synchronously:YES];
567567
}
568568

569-
- (void)getDelegate:(id *)delegatePtr delegateQueue:(dispatch_queue_t *)delegateQueuePtr
569+
- (void)getDelegate:(id <GCDAsyncUdpSocketDelegate> *)delegatePtr delegateQueue:(dispatch_queue_t *)delegateQueuePtr
570570
{
571571
if (dispatch_get_specific(IsOnSocketQueueOrTargetQueueKey))
572572
{
@@ -588,7 +588,7 @@ - (void)getDelegate:(id *)delegatePtr delegateQueue:(dispatch_queue_t *)delegate
588588
}
589589
}
590590

591-
- (void)setDelegate:(id)newDelegate delegateQueue:(dispatch_queue_t)newDelegateQueue synchronously:(BOOL)synchronously
591+
- (void)setDelegate:(id <GCDAsyncUdpSocketDelegate>)newDelegate delegateQueue:(dispatch_queue_t)newDelegateQueue synchronously:(BOOL)synchronously
592592
{
593593
dispatch_block_t block = ^{
594594

@@ -613,12 +613,12 @@ - (void)setDelegate:(id)newDelegate delegateQueue:(dispatch_queue_t)newDelegateQ
613613
}
614614
}
615615

616-
- (void)setDelegate:(id)newDelegate delegateQueue:(dispatch_queue_t)newDelegateQueue
616+
- (void)setDelegate:(id <GCDAsyncUdpSocketDelegate>)newDelegate delegateQueue:(dispatch_queue_t)newDelegateQueue
617617
{
618618
[self setDelegate:newDelegate delegateQueue:newDelegateQueue synchronously:NO];
619619
}
620620

621-
- (void)synchronouslySetDelegate:(id)newDelegate delegateQueue:(dispatch_queue_t)newDelegateQueue
621+
- (void)synchronouslySetDelegate:(id <GCDAsyncUdpSocketDelegate>)newDelegate delegateQueue:(dispatch_queue_t)newDelegateQueue
622622
{
623623
[self setDelegate:newDelegate delegateQueue:newDelegateQueue synchronously:YES];
624624
}

0 commit comments

Comments
 (0)