@@ -28,6 +28,59 @@ typedef NS_ENUM(NSInteger, GCDAsyncUdpSocketError) {
28
28
GCDAsyncUdpSocketOtherError, // Description provided in userInfo
29
29
};
30
30
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
+
31
84
/* *
32
85
* You may optionally set a receive filter for the socket.
33
86
* A filter can provide several useful features:
@@ -126,22 +179,22 @@ typedef BOOL (^GCDAsyncUdpSocketSendFilterBlock)(NSData *data, NSData *address,
126
179
**/
127
180
- (id )init ;
128
181
- (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 ;
131
184
132
185
#pragma mark Configuration
133
186
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 ;
137
190
138
191
- (dispatch_queue_t )delegateQueue ;
139
192
- (void )setDelegateQueue : (dispatch_queue_t )delegateQueue ;
140
193
- (void )synchronouslySetDelegateQueue : (dispatch_queue_t )delegateQueue ;
141
194
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 ;
145
198
146
199
/* *
147
200
* By default, both IPv4 and IPv6 are enabled.
@@ -941,54 +994,3 @@ typedef BOOL (^GCDAsyncUdpSocketSendFilterBlock)(NSData *data, NSData *address,
941
994
942
995
@end
943
996
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
-
0 commit comments