PageRenderTime 28ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/XMPP_Demo/Vendor/CocoaAsyncSocket/GCDAsyncSocket.h

https://gitlab.com/praveenvelanati/ios-demo
C Header | 1046 lines | 238 code | 111 blank | 697 comment | 0 complexity | 96121e92fd9afc5fb41b9bcbc7b828c7 MD5 | raw file
  1. //
  2. // GCDAsyncSocket.h
  3. //
  4. // This class is in the public domain.
  5. // Originally created by Robbie Hanson in Q3 2010.
  6. // Updated and maintained by Deusty LLC and the Apple development community.
  7. //
  8. // https://github.com/robbiehanson/CocoaAsyncSocket
  9. //
  10. #import <Foundation/Foundation.h>
  11. #import <Security/Security.h>
  12. #import <Security/SecureTransport.h>
  13. #import <dispatch/dispatch.h>
  14. @class GCDAsyncReadPacket;
  15. @class GCDAsyncWritePacket;
  16. @class GCDAsyncSocketPreBuffer;
  17. #if TARGET_OS_IPHONE
  18. // Compiling for iOS
  19. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 // iOS 5.0 supported
  20. #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 50000 // iOS 5.0 supported and required
  21. #define IS_SECURE_TRANSPORT_AVAILABLE YES
  22. #define SECURE_TRANSPORT_MAYBE_AVAILABLE 1
  23. #define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 0
  24. #else // iOS 5.0 supported but not required
  25. #ifndef NSFoundationVersionNumber_iPhoneOS_5_0
  26. #define NSFoundationVersionNumber_iPhoneOS_5_0 881.00
  27. #endif
  28. #define IS_SECURE_TRANSPORT_AVAILABLE (NSFoundationVersionNumber >= NSFoundationVersionNumber_iPhoneOS_5_0)
  29. #define SECURE_TRANSPORT_MAYBE_AVAILABLE 1
  30. #define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 1
  31. #endif
  32. #else // iOS 5.0 not supported
  33. #define IS_SECURE_TRANSPORT_AVAILABLE NO
  34. #define SECURE_TRANSPORT_MAYBE_AVAILABLE 0
  35. #define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 1
  36. #endif
  37. #else
  38. // Compiling for Mac OS X
  39. #define IS_SECURE_TRANSPORT_AVAILABLE YES
  40. #define SECURE_TRANSPORT_MAYBE_AVAILABLE 1
  41. #define SECURE_TRANSPORT_MAYBE_UNAVAILABLE 0
  42. #endif
  43. extern NSString *const GCDAsyncSocketException;
  44. extern NSString *const GCDAsyncSocketErrorDomain;
  45. extern NSString *const GCDAsyncSocketQueueName;
  46. extern NSString *const GCDAsyncSocketThreadName;
  47. #if SECURE_TRANSPORT_MAYBE_AVAILABLE
  48. extern NSString *const GCDAsyncSocketSSLCipherSuites;
  49. #if TARGET_OS_IPHONE
  50. extern NSString *const GCDAsyncSocketSSLProtocolVersionMin;
  51. extern NSString *const GCDAsyncSocketSSLProtocolVersionMax;
  52. #else
  53. extern NSString *const GCDAsyncSocketSSLDiffieHellmanParameters;
  54. #endif
  55. #endif
  56. enum GCDAsyncSocketError
  57. {
  58. GCDAsyncSocketNoError = 0, // Never used
  59. GCDAsyncSocketBadConfigError, // Invalid configuration
  60. GCDAsyncSocketBadParamError, // Invalid parameter was passed
  61. GCDAsyncSocketConnectTimeoutError, // A connect operation timed out
  62. GCDAsyncSocketReadTimeoutError, // A read operation timed out
  63. GCDAsyncSocketWriteTimeoutError, // A write operation timed out
  64. GCDAsyncSocketReadMaxedOutError, // Reached set maxLength without completing
  65. GCDAsyncSocketClosedError, // The remote peer closed the connection
  66. GCDAsyncSocketOtherError, // Description provided in userInfo
  67. };
  68. typedef enum GCDAsyncSocketError GCDAsyncSocketError;
  69. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  70. #pragma mark -
  71. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  72. @interface GCDAsyncSocket : NSObject
  73. {
  74. uint32_t flags;
  75. uint16_t config;
  76. #if __has_feature(objc_arc_weak)
  77. __weak id delegate;
  78. #else
  79. __unsafe_unretained id delegate;
  80. #endif
  81. dispatch_queue_t delegateQueue;
  82. int socket4FD;
  83. int socket6FD;
  84. int connectIndex;
  85. NSData * connectInterface4;
  86. NSData * connectInterface6;
  87. dispatch_queue_t socketQueue;
  88. dispatch_source_t accept4Source;
  89. dispatch_source_t accept6Source;
  90. dispatch_source_t connectTimer;
  91. dispatch_source_t readSource;
  92. dispatch_source_t writeSource;
  93. dispatch_source_t readTimer;
  94. dispatch_source_t writeTimer;
  95. NSMutableArray *readQueue;
  96. NSMutableArray *writeQueue;
  97. GCDAsyncReadPacket *currentRead;
  98. GCDAsyncWritePacket *currentWrite;
  99. unsigned long socketFDBytesAvailable;
  100. GCDAsyncSocketPreBuffer *preBuffer;
  101. #if TARGET_OS_IPHONE
  102. CFStreamClientContext streamContext;
  103. CFReadStreamRef readStream;
  104. CFWriteStreamRef writeStream;
  105. #endif
  106. #if SECURE_TRANSPORT_MAYBE_AVAILABLE
  107. SSLContextRef sslContext;
  108. GCDAsyncSocketPreBuffer *sslPreBuffer;
  109. size_t sslWriteCachedLength;
  110. OSStatus sslErrCode;
  111. #endif
  112. id userData;
  113. }
  114. /**
  115. * GCDAsyncSocket uses the standard delegate paradigm,
  116. * but executes all delegate callbacks on a given delegate dispatch queue.
  117. * This allows for maximum concurrency, while at the same time providing easy thread safety.
  118. *
  119. * You MUST set a delegate AND delegate dispatch queue before attempting to
  120. * use the socket, or you will get an error.
  121. *
  122. * The socket queue is optional.
  123. * If you pass NULL, GCDAsyncSocket will automatically create it's own socket queue.
  124. * If you choose to provide a socket queue, the socket queue must not be a concurrent queue.
  125. *
  126. * The delegate queue and socket queue can optionally be the same.
  127. **/
  128. - (id)init;
  129. - (id)initWithSocketQueue:(dispatch_queue_t)sq;
  130. - (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq;
  131. - (id)initWithDelegate:(id)aDelegate delegateQueue:(dispatch_queue_t)dq socketQueue:(dispatch_queue_t)sq;
  132. #pragma mark Configuration
  133. - (id)delegate;
  134. - (void)setDelegate:(id)delegate;
  135. - (void)synchronouslySetDelegate:(id)delegate;
  136. - (dispatch_queue_t)delegateQueue;
  137. - (void)setDelegateQueue:(dispatch_queue_t)delegateQueue;
  138. - (void)synchronouslySetDelegateQueue:(dispatch_queue_t)delegateQueue;
  139. - (void)getDelegate:(id *)delegatePtr delegateQueue:(dispatch_queue_t *)delegateQueuePtr;
  140. - (void)setDelegate:(id)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
  141. - (void)synchronouslySetDelegate:(id)delegate delegateQueue:(dispatch_queue_t)delegateQueue;
  142. /**
  143. * Traditionally sockets are not closed until the conversation is over.
  144. * However, it is technically possible for the remote enpoint to close its write stream.
  145. * Our socket would then be notified that there is no more data to be read,
  146. * but our socket would still be writeable and the remote endpoint could continue to receive our data.
  147. *
  148. * The argument for this confusing functionality stems from the idea that a client could shut down its
  149. * write stream after sending a request to the server, thus notifying the server there are to be no further requests.
  150. * In practice, however, this technique did little to help server developers.
  151. *
  152. * To make matters worse, from a TCP perspective there is no way to tell the difference from a read stream close
  153. * and a full socket close. They both result in the TCP stack receiving a FIN packet. The only way to tell
  154. * is by continuing to write to the socket. If it was only a read stream close, then writes will continue to work.
  155. * Otherwise an error will be occur shortly (when the remote end sends us a RST packet).
  156. *
  157. * In addition to the technical challenges and confusion, many high level socket/stream API's provide
  158. * no support for dealing with the problem. If the read stream is closed, the API immediately declares the
  159. * socket to be closed, and shuts down the write stream as well. In fact, this is what Apple's CFStream API does.
  160. * It might sound like poor design at first, but in fact it simplifies development.
  161. *
  162. * The vast majority of the time if the read stream is closed it's because the remote endpoint closed its socket.
  163. * Thus it actually makes sense to close the socket at this point.
  164. * And in fact this is what most networking developers want and expect to happen.
  165. * However, if you are writing a server that interacts with a plethora of clients,
  166. * you might encounter a client that uses the discouraged technique of shutting down its write stream.
  167. * If this is the case, you can set this property to NO,
  168. * and make use of the socketDidCloseReadStream delegate method.
  169. *
  170. * The default value is YES.
  171. **/
  172. - (BOOL)autoDisconnectOnClosedReadStream;
  173. - (void)setAutoDisconnectOnClosedReadStream:(BOOL)flag;
  174. /**
  175. * By default, both IPv4 and IPv6 are enabled.
  176. *
  177. * For accepting incoming connections, this means GCDAsyncSocket automatically supports both protocols,
  178. * and can simulataneously accept incoming connections on either protocol.
  179. *
  180. * For outgoing connections, this means GCDAsyncSocket can connect to remote hosts running either protocol.
  181. * If a DNS lookup returns only IPv4 results, GCDAsyncSocket will automatically use IPv4.
  182. * If a DNS lookup returns only IPv6 results, GCDAsyncSocket will automatically use IPv6.
  183. * If a DNS lookup returns both IPv4 and IPv6 results, the preferred protocol will be chosen.
  184. * By default, the preferred protocol is IPv4, but may be configured as desired.
  185. **/
  186. - (BOOL)isIPv4Enabled;
  187. - (void)setIPv4Enabled:(BOOL)flag;
  188. - (BOOL)isIPv6Enabled;
  189. - (void)setIPv6Enabled:(BOOL)flag;
  190. - (BOOL)isIPv4PreferredOverIPv6;
  191. - (void)setPreferIPv4OverIPv6:(BOOL)flag;
  192. /**
  193. * User data allows you to associate arbitrary information with the socket.
  194. * This data is not used internally by socket in any way.
  195. **/
  196. - (id)userData;
  197. - (void)setUserData:(id)arbitraryUserData;
  198. #pragma mark Accepting
  199. /**
  200. * Tells the socket to begin listening and accepting connections on the given port.
  201. * When a connection is accepted, a new instance of GCDAsyncSocket will be spawned to handle it,
  202. * and the socket:didAcceptNewSocket: delegate method will be invoked.
  203. *
  204. * The socket will listen on all available interfaces (e.g. wifi, ethernet, etc)
  205. **/
  206. - (BOOL)acceptOnPort:(uint16_t)port error:(NSError **)errPtr;
  207. /**
  208. * This method is the same as acceptOnPort:error: with the
  209. * additional option of specifying which interface to listen on.
  210. *
  211. * For example, you could specify that the socket should only accept connections over ethernet,
  212. * and not other interfaces such as wifi.
  213. *
  214. * The interface may be specified by name (e.g. "en1" or "lo0") or by IP address (e.g. "192.168.4.34").
  215. * You may also use the special strings "localhost" or "loopback" to specify that
  216. * the socket only accept connections from the local machine.
  217. *
  218. * You can see the list of interfaces via the command line utility "ifconfig",
  219. * or programmatically via the getifaddrs() function.
  220. *
  221. * To accept connections on any interface pass nil, or simply use the acceptOnPort:error: method.
  222. **/
  223. - (BOOL)acceptOnInterface:(NSString *)interface port:(uint16_t)port error:(NSError **)errPtr;
  224. #pragma mark Connecting
  225. /**
  226. * Connects to the given host and port.
  227. *
  228. * This method invokes connectToHost:onPort:viaInterface:withTimeout:error:
  229. * and uses the default interface, and no timeout.
  230. **/
  231. - (BOOL)connectToHost:(NSString *)host onPort:(uint16_t)port error:(NSError **)errPtr;
  232. /**
  233. * Connects to the given host and port with an optional timeout.
  234. *
  235. * This method invokes connectToHost:onPort:viaInterface:withTimeout:error: and uses the default interface.
  236. **/
  237. - (BOOL)connectToHost:(NSString *)host
  238. onPort:(uint16_t)port
  239. withTimeout:(NSTimeInterval)timeout
  240. error:(NSError **)errPtr;
  241. /**
  242. * Connects to the given host & port, via the optional interface, with an optional timeout.
  243. *
  244. * The host may be a domain name (e.g. "deusty.com") or an IP address string (e.g. "192.168.0.2").
  245. * The host may also be the special strings "localhost" or "loopback" to specify connecting
  246. * to a service on the local machine.
  247. *
  248. * The interface may be a name (e.g. "en1" or "lo0") or the corresponding IP address (e.g. "192.168.4.35").
  249. * The interface may also be used to specify the local port (see below).
  250. *
  251. * To not time out use a negative time interval.
  252. *
  253. * This method will return NO if an error is detected, and set the error pointer (if one was given).
  254. * Possible errors would be a nil host, invalid interface, or socket is already connected.
  255. *
  256. * If no errors are detected, this method will start a background connect operation and immediately return YES.
  257. * The delegate callbacks are used to notify you when the socket connects, or if the host was unreachable.
  258. *
  259. * Since this class supports queued reads and writes, you can immediately start reading and/or writing.
  260. * All read/write operations will be queued, and upon socket connection,
  261. * the operations will be dequeued and processed in order.
  262. *
  263. * The interface may optionally contain a port number at the end of the string, separated by a colon.
  264. * This allows you to specify the local port that should be used for the outgoing connection. (read paragraph to end)
  265. * To specify both interface and local port: "en1:8082" or "192.168.4.35:2424".
  266. * To specify only local port: ":8082".
  267. * Please note this is an advanced feature, and is somewhat hidden on purpose.
  268. * You should understand that 99.999% of the time you should NOT specify the local port for an outgoing connection.
  269. * If you think you need to, there is a very good chance you have a fundamental misunderstanding somewhere.
  270. * Local ports do NOT need to match remote ports. In fact, they almost never do.
  271. * This feature is here for networking professionals using very advanced techniques.
  272. **/
  273. - (BOOL)connectToHost:(NSString *)host
  274. onPort:(uint16_t)port
  275. viaInterface:(NSString *)interface
  276. withTimeout:(NSTimeInterval)timeout
  277. error:(NSError **)errPtr;
  278. /**
  279. * Connects to the given address, specified as a sockaddr structure wrapped in a NSData object.
  280. * For example, a NSData object returned from NSNetService's addresses method.
  281. *
  282. * If you have an existing struct sockaddr you can convert it to a NSData object like so:
  283. * struct sockaddr sa -> NSData *dsa = [NSData dataWithBytes:&remoteAddr length:remoteAddr.sa_len];
  284. * struct sockaddr *sa -> NSData *dsa = [NSData dataWithBytes:remoteAddr length:remoteAddr->sa_len];
  285. *
  286. * This method invokes connectToAdd
  287. **/
  288. - (BOOL)connectToAddress:(NSData *)remoteAddr error:(NSError **)errPtr;
  289. /**
  290. * This method is the same as connectToAddress:error: with an additional timeout option.
  291. * To not time out use a negative time interval, or simply use the connectToAddress:error: method.
  292. **/
  293. - (BOOL)connectToAddress:(NSData *)remoteAddr withTimeout:(NSTimeInterval)timeout error:(NSError **)errPtr;
  294. /**
  295. * Connects to the given address, using the specified interface and timeout.
  296. *
  297. * The address is specified as a sockaddr structure wrapped in a NSData object.
  298. * For example, a NSData object returned from NSNetService's addresses method.
  299. *
  300. * If you have an existing struct sockaddr you can convert it to a NSData object like so:
  301. * struct sockaddr sa -> NSData *dsa = [NSData dataWithBytes:&remoteAddr length:remoteAddr.sa_len];
  302. * struct sockaddr *sa -> NSData *dsa = [NSData dataWithBytes:remoteAddr length:remoteAddr->sa_len];
  303. *
  304. * The interface may be a name (e.g. "en1" or "lo0") or the corresponding IP address (e.g. "192.168.4.35").
  305. * The interface may also be used to specify the local port (see below).
  306. *
  307. * The timeout is optional. To not time out use a negative time interval.
  308. *
  309. * This method will return NO if an error is detected, and set the error pointer (if one was given).
  310. * Possible errors would be a nil host, invalid interface, or socket is already connected.
  311. *
  312. * If no errors are detected, this method will start a background connect operation and immediately return YES.
  313. * The delegate callbacks are used to notify you when the socket connects, or if the host was unreachable.
  314. *
  315. * Since this class supports queued reads and writes, you can immediately start reading and/or writing.
  316. * All read/write operations will be queued, and upon socket connection,
  317. * the operations will be dequeued and processed in order.
  318. *
  319. * The interface may optionally contain a port number at the end of the string, separated by a colon.
  320. * This allows you to specify the local port that should be used for the outgoing connection. (read paragraph to end)
  321. * To specify both interface and local port: "en1:8082" or "192.168.4.35:2424".
  322. * To specify only local port: ":8082".
  323. * Please note this is an advanced feature, and is somewhat hidden on purpose.
  324. * You should understand that 99.999% of the time you should NOT specify the local port for an outgoing connection.
  325. * If you think you need to, there is a very good chance you have a fundamental misunderstanding somewhere.
  326. * Local ports do NOT need to match remote ports. In fact, they almost never do.
  327. * This feature is here for networking professionals using very advanced techniques.
  328. **/
  329. - (BOOL)connectToAddress:(NSData *)remoteAddr
  330. viaInterface:(NSString *)interface
  331. withTimeout:(NSTimeInterval)timeout
  332. error:(NSError **)errPtr;
  333. #pragma mark Disconnecting
  334. /**
  335. * Disconnects immediately (synchronously). Any pending reads or writes are dropped.
  336. *
  337. * If the socket is not already disconnected, an invocation to the socketDidDisconnect:withError: delegate method
  338. * will be queued onto the delegateQueue asynchronously (behind any previously queued delegate methods).
  339. * In other words, the disconnected delegate method will be invoked sometime shortly after this method returns.
  340. *
  341. * Please note the recommended way of releasing a GCDAsyncSocket instance (e.g. in a dealloc method)
  342. * [asyncSocket setDelegate:nil];
  343. * [asyncSocket disconnect];
  344. * [asyncSocket release];
  345. *
  346. * If you plan on disconnecting the socket, and then immediately asking it to connect again,
  347. * you'll likely want to do so like this:
  348. * [asyncSocket setDelegate:nil];
  349. * [asyncSocket disconnect];
  350. * [asyncSocket setDelegate:self];
  351. * [asyncSocket connect...];
  352. **/
  353. - (void)disconnect;
  354. /**
  355. * Disconnects after all pending reads have completed.
  356. * After calling this, the read and write methods will do nothing.
  357. * The socket will disconnect even if there are still pending writes.
  358. **/
  359. - (void)disconnectAfterReading;
  360. /**
  361. * Disconnects after all pending writes have completed.
  362. * After calling this, the read and write methods will do nothing.
  363. * The socket will disconnect even if there are still pending reads.
  364. **/
  365. - (void)disconnectAfterWriting;
  366. /**
  367. * Disconnects after all pending reads and writes have completed.
  368. * After calling this, the read and write methods will do nothing.
  369. **/
  370. - (void)disconnectAfterReadingAndWriting;
  371. #pragma mark Diagnostics
  372. /**
  373. * Returns whether the socket is disconnected or connected.
  374. *
  375. * A disconnected socket may be recycled.
  376. * That is, it can used again for connecting or listening.
  377. *
  378. * If a socket is in the process of connecting, it may be neither disconnected nor connected.
  379. **/
  380. - (BOOL)isDisconnected;
  381. - (BOOL)isConnected;
  382. /**
  383. * Returns the local or remote host and port to which this socket is connected, or nil and 0 if not connected.
  384. * The host will be an IP address.
  385. **/
  386. - (NSString *)connectedHost;
  387. - (uint16_t)connectedPort;
  388. - (NSString *)localHost;
  389. - (uint16_t)localPort;
  390. /**
  391. * Returns the local or remote address to which this socket is connected,
  392. * specified as a sockaddr structure wrapped in a NSData object.
  393. *
  394. * See also the connectedHost, connectedPort, localHost and localPort methods.
  395. **/
  396. - (NSData *)connectedAddress;
  397. - (NSData *)localAddress;
  398. /**
  399. * Returns whether the socket is IPv4 or IPv6.
  400. * An accepting socket may be both.
  401. **/
  402. - (BOOL)isIPv4;
  403. - (BOOL)isIPv6;
  404. /**
  405. * Returns whether or not the socket has been secured via SSL/TLS.
  406. *
  407. * See also the startTLS method.
  408. **/
  409. - (BOOL)isSecure;
  410. #pragma mark Reading
  411. // The readData and writeData methods won't block (they are asynchronous).
  412. //
  413. // When a read is complete the socket:didReadData:withTag: delegate method is dispatched on the delegateQueue.
  414. // When a write is complete the socket:didWriteDataWithTag: delegate method is dispatched on the delegateQueue.
  415. //
  416. // You may optionally set a timeout for any read/write operation. (To not timeout, use a negative time interval.)
  417. // If a read/write opertion times out, the corresponding "socket:shouldTimeout..." delegate method
  418. // is called to optionally allow you to extend the timeout.
  419. // Upon a timeout, the "socket:didDisconnectWithError:" method is called
  420. //
  421. // The tag is for your convenience.
  422. // You can use it as an array index, step number, state id, pointer, etc.
  423. /**
  424. * Reads the first available bytes that become available on the socket.
  425. *
  426. * If the timeout value is negative, the read operation will not use a timeout.
  427. **/
  428. - (void)readDataWithTimeout:(NSTimeInterval)timeout tag:(long)tag;
  429. /**
  430. * Reads the first available bytes that become available on the socket.
  431. * The bytes will be appended to the given byte buffer starting at the given offset.
  432. * The given buffer will automatically be increased in size if needed.
  433. *
  434. * If the timeout value is negative, the read operation will not use a timeout.
  435. * If the buffer if nil, the socket will create a buffer for you.
  436. *
  437. * If the bufferOffset is greater than the length of the given buffer,
  438. * the method will do nothing, and the delegate will not be called.
  439. *
  440. * If you pass a buffer, you must not alter it in any way while the socket is using it.
  441. * After completion, the data returned in socket:didReadData:withTag: will be a subset of the given buffer.
  442. * That is, it will reference the bytes that were appended to the given buffer via
  443. * the method [NSData dataWithBytesNoCopy:length:freeWhenDone:NO].
  444. **/
  445. - (void)readDataWithTimeout:(NSTimeInterval)timeout
  446. buffer:(NSMutableData *)buffer
  447. bufferOffset:(NSUInteger)offset
  448. tag:(long)tag;
  449. /**
  450. * Reads the first available bytes that become available on the socket.
  451. * The bytes will be appended to the given byte buffer starting at the given offset.
  452. * The given buffer will automatically be increased in size if needed.
  453. * A maximum of length bytes will be read.
  454. *
  455. * If the timeout value is negative, the read operation will not use a timeout.
  456. * If the buffer if nil, a buffer will automatically be created for you.
  457. * If maxLength is zero, no length restriction is enforced.
  458. *
  459. * If the bufferOffset is greater than the length of the given buffer,
  460. * the method will do nothing, and the delegate will not be called.
  461. *
  462. * If you pass a buffer, you must not alter it in any way while the socket is using it.
  463. * After completion, the data returned in socket:didReadData:withTag: will be a subset of the given buffer.
  464. * That is, it will reference the bytes that were appended to the given buffer via
  465. * the method [NSData dataWithBytesNoCopy:length:freeWhenDone:NO].
  466. **/
  467. - (void)readDataWithTimeout:(NSTimeInterval)timeout
  468. buffer:(NSMutableData *)buffer
  469. bufferOffset:(NSUInteger)offset
  470. maxLength:(NSUInteger)length
  471. tag:(long)tag;
  472. /**
  473. * Reads the given number of bytes.
  474. *
  475. * If the timeout value is negative, the read operation will not use a timeout.
  476. *
  477. * If the length is 0, this method does nothing and the delegate is not called.
  478. **/
  479. - (void)readDataToLength:(NSUInteger)length withTimeout:(NSTimeInterval)timeout tag:(long)tag;
  480. /**
  481. * Reads the given number of bytes.
  482. * The bytes will be appended to the given byte buffer starting at the given offset.
  483. * The given buffer will automatically be increased in size if needed.
  484. *
  485. * If the timeout value is negative, the read operation will not use a timeout.
  486. * If the buffer if nil, a buffer will automatically be created for you.
  487. *
  488. * If the length is 0, this method does nothing and the delegate is not called.
  489. * If the bufferOffset is greater than the length of the given buffer,
  490. * the method will do nothing, and the delegate will not be called.
  491. *
  492. * If you pass a buffer, you must not alter it in any way while AsyncSocket is using it.
  493. * After completion, the data returned in socket:didReadData:withTag: will be a subset of the given buffer.
  494. * That is, it will reference the bytes that were appended to the given buffer via
  495. * the method [NSData dataWithBytesNoCopy:length:freeWhenDone:NO].
  496. **/
  497. - (void)readDataToLength:(NSUInteger)length
  498. withTimeout:(NSTimeInterval)timeout
  499. buffer:(NSMutableData *)buffer
  500. bufferOffset:(NSUInteger)offset
  501. tag:(long)tag;
  502. /**
  503. * Reads bytes until (and including) the passed "data" parameter, which acts as a separator.
  504. *
  505. * If the timeout value is negative, the read operation will not use a timeout.
  506. *
  507. * If you pass nil or zero-length data as the "data" parameter,
  508. * the method will do nothing (except maybe print a warning), and the delegate will not be called.
  509. *
  510. * To read a line from the socket, use the line separator (e.g. CRLF for HTTP, see below) as the "data" parameter.
  511. * If you're developing your own custom protocol, be sure your separator can not occur naturally as
  512. * part of the data between separators.
  513. * For example, imagine you want to send several small documents over a socket.
  514. * Using CRLF as a separator is likely unwise, as a CRLF could easily exist within the documents.
  515. * In this particular example, it would be better to use a protocol similar to HTTP with
  516. * a header that includes the length of the document.
  517. * Also be careful that your separator cannot occur naturally as part of the encoding for a character.
  518. *
  519. * The given data (separator) parameter should be immutable.
  520. * For performance reasons, the socket will retain it, not copy it.
  521. * So if it is immutable, don't modify it while the socket is using it.
  522. **/
  523. - (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;
  524. /**
  525. * Reads bytes until (and including) the passed "data" parameter, which acts as a separator.
  526. * The bytes will be appended to the given byte buffer starting at the given offset.
  527. * The given buffer will automatically be increased in size if needed.
  528. *
  529. * If the timeout value is negative, the read operation will not use a timeout.
  530. * If the buffer if nil, a buffer will automatically be created for you.
  531. *
  532. * If the bufferOffset is greater than the length of the given buffer,
  533. * the method will do nothing (except maybe print a warning), and the delegate will not be called.
  534. *
  535. * If you pass a buffer, you must not alter it in any way while the socket is using it.
  536. * After completion, the data returned in socket:didReadData:withTag: will be a subset of the given buffer.
  537. * That is, it will reference the bytes that were appended to the given buffer via
  538. * the method [NSData dataWithBytesNoCopy:length:freeWhenDone:NO].
  539. *
  540. * To read a line from the socket, use the line separator (e.g. CRLF for HTTP, see below) as the "data" parameter.
  541. * If you're developing your own custom protocol, be sure your separator can not occur naturally as
  542. * part of the data between separators.
  543. * For example, imagine you want to send several small documents over a socket.
  544. * Using CRLF as a separator is likely unwise, as a CRLF could easily exist within the documents.
  545. * In this particular example, it would be better to use a protocol similar to HTTP with
  546. * a header that includes the length of the document.
  547. * Also be careful that your separator cannot occur naturally as part of the encoding for a character.
  548. *
  549. * The given data (separator) parameter should be immutable.
  550. * For performance reasons, the socket will retain it, not copy it.
  551. * So if it is immutable, don't modify it while the socket is using it.
  552. **/
  553. - (void)readDataToData:(NSData *)data
  554. withTimeout:(NSTimeInterval)timeout
  555. buffer:(NSMutableData *)buffer
  556. bufferOffset:(NSUInteger)offset
  557. tag:(long)tag;
  558. /**
  559. * Reads bytes until (and including) the passed "data" parameter, which acts as a separator.
  560. *
  561. * If the timeout value is negative, the read operation will not use a timeout.
  562. *
  563. * If maxLength is zero, no length restriction is enforced.
  564. * Otherwise if maxLength bytes are read without completing the read,
  565. * it is treated similarly to a timeout - the socket is closed with a GCDAsyncSocketReadMaxedOutError.
  566. * The read will complete successfully if exactly maxLength bytes are read and the given data is found at the end.
  567. *
  568. * If you pass nil or zero-length data as the "data" parameter,
  569. * the method will do nothing (except maybe print a warning), and the delegate will not be called.
  570. * If you pass a maxLength parameter that is less than the length of the data parameter,
  571. * the method will do nothing (except maybe print a warning), and the delegate will not be called.
  572. *
  573. * To read a line from the socket, use the line separator (e.g. CRLF for HTTP, see below) as the "data" parameter.
  574. * If you're developing your own custom protocol, be sure your separator can not occur naturally as
  575. * part of the data between separators.
  576. * For example, imagine you want to send several small documents over a socket.
  577. * Using CRLF as a separator is likely unwise, as a CRLF could easily exist within the documents.
  578. * In this particular example, it would be better to use a protocol similar to HTTP with
  579. * a header that includes the length of the document.
  580. * Also be careful that your separator cannot occur naturally as part of the encoding for a character.
  581. *
  582. * The given data (separator) parameter should be immutable.
  583. * For performance reasons, the socket will retain it, not copy it.
  584. * So if it is immutable, don't modify it while the socket is using it.
  585. **/
  586. - (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout maxLength:(NSUInteger)length tag:(long)tag;
  587. /**
  588. * Reads bytes until (and including) the passed "data" parameter, which acts as a separator.
  589. * The bytes will be appended to the given byte buffer starting at the given offset.
  590. * The given buffer will automatically be increased in size if needed.
  591. *
  592. * If the timeout value is negative, the read operation will not use a timeout.
  593. * If the buffer if nil, a buffer will automatically be created for you.
  594. *
  595. * If maxLength is zero, no length restriction is enforced.
  596. * Otherwise if maxLength bytes are read without completing the read,
  597. * it is treated similarly to a timeout - the socket is closed with a GCDAsyncSocketReadMaxedOutError.
  598. * The read will complete successfully if exactly maxLength bytes are read and the given data is found at the end.
  599. *
  600. * If you pass a maxLength parameter that is less than the length of the data (separator) parameter,
  601. * the method will do nothing (except maybe print a warning), and the delegate will not be called.
  602. * If the bufferOffset is greater than the length of the given buffer,
  603. * the method will do nothing (except maybe print a warning), and the delegate will not be called.
  604. *
  605. * If you pass a buffer, you must not alter it in any way while the socket is using it.
  606. * After completion, the data returned in socket:didReadData:withTag: will be a subset of the given buffer.
  607. * That is, it will reference the bytes that were appended to the given buffer via
  608. * the method [NSData dataWithBytesNoCopy:length:freeWhenDone:NO].
  609. *
  610. * To read a line from the socket, use the line separator (e.g. CRLF for HTTP, see below) as the "data" parameter.
  611. * If you're developing your own custom protocol, be sure your separator can not occur naturally as
  612. * part of the data between separators.
  613. * For example, imagine you want to send several small documents over a socket.
  614. * Using CRLF as a separator is likely unwise, as a CRLF could easily exist within the documents.
  615. * In this particular example, it would be better to use a protocol similar to HTTP with
  616. * a header that includes the length of the document.
  617. * Also be careful that your separator cannot occur naturally as part of the encoding for a character.
  618. *
  619. * The given data (separator) parameter should be immutable.
  620. * For performance reasons, the socket will retain it, not copy it.
  621. * So if it is immutable, don't modify it while the socket is using it.
  622. **/
  623. - (void)readDataToData:(NSData *)data
  624. withTimeout:(NSTimeInterval)timeout
  625. buffer:(NSMutableData *)buffer
  626. bufferOffset:(NSUInteger)offset
  627. maxLength:(NSUInteger)length
  628. tag:(long)tag;
  629. /**
  630. * Returns progress of the current read, from 0.0 to 1.0, or NaN if no current read (use isnan() to check).
  631. * The parameters "tag", "done" and "total" will be filled in if they aren't NULL.
  632. **/
  633. - (float)progressOfReadReturningTag:(long *)tagPtr bytesDone:(NSUInteger *)donePtr total:(NSUInteger *)totalPtr;
  634. #pragma mark Writing
  635. /**
  636. * Writes data to the socket, and calls the delegate when finished.
  637. *
  638. * If you pass in nil or zero-length data, this method does nothing and the delegate will not be called.
  639. * If the timeout value is negative, the write operation will not use a timeout.
  640. *
  641. * Thread-Safety Note:
  642. * If the given data parameter is mutable (NSMutableData) then you MUST NOT alter the data while
  643. * the socket is writing it. In other words, it's not safe to alter the data until after the delegate method
  644. * socket:didWriteDataWithTag: is invoked signifying that this particular write operation has completed.
  645. * This is due to the fact that GCDAsyncSocket does NOT copy the data. It simply retains it.
  646. * This is for performance reasons. Often times, if NSMutableData is passed, it is because
  647. * a request/response was built up in memory. Copying this data adds an unwanted/unneeded overhead.
  648. * If you need to write data from an immutable buffer, and you need to alter the buffer before the socket
  649. * completes writing the bytes (which is NOT immediately after this method returns, but rather at a later time
  650. * when the delegate method notifies you), then you should first copy the bytes, and pass the copy to this method.
  651. **/
  652. - (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;
  653. /**
  654. * Returns progress of the current write, from 0.0 to 1.0, or NaN if no current write (use isnan() to check).
  655. * The parameters "tag", "done" and "total" will be filled in if they aren't NULL.
  656. **/
  657. - (float)progressOfWriteReturningTag:(long *)tagPtr bytesDone:(NSUInteger *)donePtr total:(NSUInteger *)totalPtr;
  658. #pragma mark Security
  659. /**
  660. * Secures the connection using SSL/TLS.
  661. *
  662. * This method may be called at any time, and the TLS handshake will occur after all pending reads and writes
  663. * are finished. This allows one the option of sending a protocol dependent StartTLS message, and queuing
  664. * the upgrade to TLS at the same time, without having to wait for the write to finish.
  665. * Any reads or writes scheduled after this method is called will occur over the secured connection.
  666. *
  667. * The possible keys and values for the TLS settings are well documented.
  668. * Standard keys are:
  669. *
  670. * - kCFStreamSSLLevel
  671. * - kCFStreamSSLAllowsExpiredCertificates
  672. * - kCFStreamSSLAllowsExpiredRoots
  673. * - kCFStreamSSLAllowsAnyRoot
  674. * - kCFStreamSSLValidatesCertificateChain
  675. * - kCFStreamSSLPeerName
  676. * - kCFStreamSSLCertificates
  677. * - kCFStreamSSLIsServer
  678. *
  679. * If SecureTransport is available on iOS:
  680. *
  681. * - GCDAsyncSocketSSLCipherSuites
  682. * - GCDAsyncSocketSSLProtocolVersionMin
  683. * - GCDAsyncSocketSSLProtocolVersionMax
  684. *
  685. * If SecureTransport is available on Mac OS X:
  686. *
  687. * - GCDAsyncSocketSSLCipherSuites
  688. * - GCDAsyncSocketSSLDiffieHellmanParameters;
  689. *
  690. *
  691. * Please refer to Apple's documentation for associated values, as well as other possible keys.
  692. *
  693. * If you pass in nil or an empty dictionary, the default settings will be used.
  694. *
  695. * The default settings will check to make sure the remote party's certificate is signed by a
  696. * trusted 3rd party certificate agency (e.g. verisign) and that the certificate is not expired.
  697. * However it will not verify the name on the certificate unless you
  698. * give it a name to verify against via the kCFStreamSSLPeerName key.
  699. * The security implications of this are important to understand.
  700. * Imagine you are attempting to create a secure connection to MySecureServer.com,
  701. * but your socket gets directed to MaliciousServer.com because of a hacked DNS server.
  702. * If you simply use the default settings, and MaliciousServer.com has a valid certificate,
  703. * the default settings will not detect any problems since the certificate is valid.
  704. * To properly secure your connection in this particular scenario you
  705. * should set the kCFStreamSSLPeerName property to "MySecureServer.com".
  706. * If you do not know the peer name of the remote host in advance (for example, you're not sure
  707. * if it will be "domain.com" or "www.domain.com"), then you can use the default settings to validate the
  708. * certificate, and then use the X509Certificate class to verify the issuer after the socket has been secured.
  709. * The X509Certificate class is part of the CocoaAsyncSocket open source project.
  710. **/
  711. - (void)startTLS:(NSDictionary *)tlsSettings;
  712. #pragma mark Advanced
  713. /**
  714. * It's not thread-safe to access certain variables from outside the socket's internal queue.
  715. *
  716. * For example, the socket file descriptor.
  717. * File descriptors are simply integers which reference an index in the per-process file table.
  718. * However, when one requests a new file descriptor (by opening a file or socket),
  719. * the file descriptor returned is guaranteed to be the lowest numbered unused descriptor.
  720. * So if we're not careful, the following could be possible:
  721. *
  722. * - Thread A invokes a method which returns the socket's file descriptor.
  723. * - The socket is closed via the socket's internal queue on thread B.
  724. * - Thread C opens a file, and subsequently receives the file descriptor that was previously the socket's FD.
  725. * - Thread A is now accessing/altering the file instead of the socket.
  726. *
  727. * In addition to this, other variables are not actually objects,
  728. * and thus cannot be retained/released or even autoreleased.
  729. * An example is the sslContext, of type SSLContextRef, which is actually a malloc'd struct.
  730. *
  731. * Although there are internal variables that make it difficult to maintain thread-safety,
  732. * it is important to provide access to these variables
  733. * to ensure this class can be used in a wide array of environments.
  734. * This method helps to accomplish this by invoking the current block on the socket's internal queue.
  735. * The methods below can be invoked from within the block to access
  736. * those generally thread-unsafe internal variables in a thread-safe manner.
  737. * The given block will be invoked synchronously on the socket's internal queue.
  738. *
  739. * If you save references to any protected variables and use them outside the block, you do so at your own peril.
  740. **/
  741. - (void)performBlock:(dispatch_block_t)block;
  742. /**
  743. * These methods are only available from within the context of a performBlock: invocation.
  744. * See the documentation for the performBlock: method above.
  745. *
  746. * Provides access to the socket's file descriptor(s).
  747. * If the socket is a server socket (is accepting incoming connections),
  748. * it might actually have multiple internal socket file descriptors - one for IPv4 and one for IPv6.
  749. **/
  750. - (int)socketFD;
  751. - (int)socket4FD;
  752. - (int)socket6FD;
  753. #if TARGET_OS_IPHONE
  754. /**
  755. * These methods are only available from within the context of a performBlock: invocation.
  756. * See the documentation for the performBlock: method above.
  757. *
  758. * Provides access to the socket's internal CFReadStream/CFWriteStream.
  759. *
  760. * These streams are only used as workarounds for specific iOS shortcomings:
  761. *
  762. * - Apple has decided to keep the SecureTransport framework private is iOS.
  763. * This means the only supplied way to do SSL/TLS is via CFStream or some other API layered on top of it.
  764. * Thus, in order to provide SSL/TLS support on iOS we are forced to rely on CFStream,
  765. * instead of the preferred and faster and more powerful SecureTransport.
  766. *
  767. * - If a socket doesn't have backgrounding enabled, and that socket is closed while the app is backgrounded,
  768. * Apple only bothers to notify us via the CFStream API.
  769. * The faster and more powerful GCD API isn't notified properly in this case.
  770. *
  771. * See also: (BOOL)enableBackgroundingOnSocket
  772. **/
  773. - (CFReadStreamRef)readStream;
  774. - (CFWriteStreamRef)writeStream;
  775. /**
  776. * This method is only available from within the context of a performBlock: invocation.
  777. * See the documentation for the performBlock: method above.
  778. *
  779. * Configures the socket to allow it to operate when the iOS application has been backgrounded.
  780. * In other words, this method creates a read & write stream, and invokes:
  781. *
  782. * CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
  783. * CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
  784. *
  785. * Returns YES if successful, NO otherwise.
  786. *
  787. * Note: Apple does not officially support backgrounding server sockets.
  788. * That is, if your socket is accepting incoming connections, Apple does not officially support
  789. * allowing iOS applications to accept incoming connections while an app is backgrounded.
  790. *
  791. * Example usage:
  792. *
  793. * - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
  794. * {
  795. * [asyncSocket performBlock:^{
  796. * [asyncSocket enableBackgroundingOnSocket];
  797. * }];
  798. * }
  799. **/
  800. - (BOOL)enableBackgroundingOnSocket;
  801. #else
  802. /**
  803. * This method is only available from within the context of a performBlock: invocation.
  804. * See the documentation for the performBlock: method above.
  805. *
  806. * Provides access to the socket's SSLContext, if SSL/TLS has been started on the socket.
  807. **/
  808. - (SSLContextRef)sslContext;
  809. #endif
  810. #pragma mark Utilities
  811. /**
  812. * Extracting host and port information from raw address data.
  813. **/
  814. + (NSString *)hostFromAddress:(NSData *)address;
  815. + (uint16_t)portFromAddress:(NSData *)address;
  816. + (BOOL)getHost:(NSString **)hostPtr port:(uint16_t *)portPtr fromAddress:(NSData *)address;
  817. /**
  818. * A few common line separators, for use with the readDataToData:... methods.
  819. **/
  820. + (NSData *)CRLFData; // 0x0D0A
  821. + (NSData *)CRData; // 0x0D
  822. + (NSData *)LFData; // 0x0A
  823. + (NSData *)ZeroData; // 0x00
  824. @end
  825. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  826. #pragma mark -
  827. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  828. @protocol GCDAsyncSocketDelegate
  829. @optional
  830. /**
  831. * This method is called immediately prior to socket:didAcceptNewSocket:.
  832. * It optionally allows a listening socket to specify the socketQueue for a new accepted socket.
  833. * If this method is not implemented, or returns NULL, the new accepted socket will create its own default queue.
  834. *
  835. * Since you cannot autorelease a dispatch_queue,
  836. * this method uses the "new" prefix in its name to specify that the returned queue has been retained.
  837. *
  838. * Thus you could do something like this in the implementation:
  839. * return dispatch_queue_create("MyQueue", NULL);
  840. *
  841. * If you are placing multiple sockets on the same queue,
  842. * then care should be taken to increment the retain count each time this method is invoked.
  843. *
  844. * For example, your implementation might look something like this:
  845. * dispatch_retain(myExistingQueue);
  846. * return myExistingQueue;
  847. **/
  848. - (dispatch_queue_t)newSocketQueueForConnectionFromAddress:(NSData *)address onSocket:(GCDAsyncSocket *)sock;
  849. /**
  850. * Called when a socket accepts a connection.
  851. * Another socket is automatically spawned to handle it.
  852. *
  853. * You must retain the newSocket if you wish to handle the connection.
  854. * Otherwise the newSocket instance will be released and the spawned connection will be closed.
  855. *
  856. * By default the new socket will have the same delegate and delegateQueue.
  857. * You may, of course, change this at any time.
  858. **/
  859. - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket;
  860. /**
  861. * Called when a socket connects and is ready for reading and writing.
  862. * The host parameter will be an IP address, not a DNS name.
  863. **/
  864. - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port;
  865. /**
  866. * Called when a socket has completed reading the requested data into memory.
  867. * Not called if there is an error.
  868. **/
  869. - (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag;
  870. /**
  871. * Called when a socket has read in data, but has not yet completed the read.
  872. * This would occur if using readToData: or readToLength: methods.
  873. * It may be used to for things such as updating progress bars.
  874. **/
  875. - (void)socket:(GCDAsyncSocket *)sock didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag;
  876. /**
  877. * Called when a socket has completed writing the requested data. Not called if there is an error.
  878. **/
  879. - (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag;
  880. /**
  881. * Called when a socket has written some data, but has not yet completed the entire write.
  882. * It may be used to for things such as updating progress bars.
  883. **/
  884. - (void)socket:(GCDAsyncSocket *)sock didWritePartialDataOfLength:(NSUInteger)partialLength tag:(long)tag;
  885. /**
  886. * Called if a read operation has reached its timeout without completing.
  887. * This method allows you to optionally extend the timeout.
  888. * If you return a positive time interval (> 0) the read's timeout will be extended by the given amount.
  889. * If you don't implement this method, or return a non-positive time interval (<= 0) the read will timeout as usual.
  890. *
  891. * The elapsed parameter is the sum of the original timeout, plus any additions previously added via this method.
  892. * The length parameter is the number of bytes that have been read so far for the read operation.
  893. *
  894. * Note that this method may be called multiple times for a single read if you return positive numbers.
  895. **/
  896. - (NSTimeInterval)socket:(GCDAsyncSocket *)sock shouldTimeoutReadWithTag:(long)tag
  897. elapsed:(NSTimeInterval)elapsed
  898. bytesDone:(NSUInteger)length;
  899. /**
  900. * Called if a write operation has reached its timeout without completing.
  901. * This method allows you to optionally extend the timeout.
  902. * If you return a positive time interval (> 0) the write's timeout will be extended by the given amount.
  903. * If you don't implement this method, or return a non-positive time interval (<= 0) the write will timeout as usual.
  904. *
  905. * The elapsed parameter is the sum of the original timeout, plus any additions previously added via this method.
  906. * The length parameter is the number of bytes that have been written so far for the write operation.
  907. *
  908. * Note that this method may be called multiple times for a single write if you return positive numbers.
  909. **/
  910. - (NSTimeInterval)socket:(GCDAsyncSocket *)sock shouldTimeoutWriteWithTag:(long)tag
  911. elapsed:(NSTimeInterval)elapsed
  912. bytesDone:(NSUInteger)length;
  913. /**
  914. * Conditionally called if the read stream closes, but the write stream may still be writeable.
  915. *
  916. * This delegate method is only called if autoDisconnectOnClosedReadStream has been set to NO.
  917. * See the discussion on the autoDisconnectOnClosedReadStream method for more information.
  918. **/
  919. - (void)socketDidCloseReadStream:(GCDAsyncSocket *)sock;
  920. /**
  921. * Called when a socket disconnects with or without error.
  922. *
  923. * If you call the disconnect method, and the socket wasn't already disconnected,
  924. * this delegate method will be called before the disconnect method returns.
  925. **/
  926. - (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err;
  927. /**
  928. * Called after the socket has successfully completed SSL/TLS negotiation.
  929. * This method is not called unless you use the provided startTLS method.
  930. *
  931. * If a SSL/TLS negotiation fails (invalid certificate, etc) then the socket will immediately close,
  932. * and the socketDidDisconnect:withError: delegate method will be called with the specific SSL error code.
  933. **/
  934. - (void)socketDidSecure:(GCDAsyncSocket *)sock;
  935. @end