AsyncSocket.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. //
  2. // AsyncSocket.h
  3. //
  4. // This class is in the public domain.
  5. // Originally created by Dustin Voss on Wed Jan 29 2003.
  6. // Updated and maintained by Deusty Designs and the Mac development community.
  7. //
  8. // http://code.google.com/p/cocoaasyncsocket/
  9. //
  10. #import <Foundation/Foundation.h>
  11. @class AsyncSocket;
  12. @class AsyncReadPacket;
  13. @class AsyncWritePacket;
  14. extern NSString *const AsyncSocketException;
  15. extern NSString *const AsyncSocketErrorDomain;
  16. enum AsyncSocketError
  17. {
  18. AsyncSocketCFSocketError = kCFSocketError, // From CFSocketError enum.
  19. AsyncSocketNoError = 0, // Never used.
  20. AsyncSocketCanceledError, // onSocketWillConnect: returned NO.
  21. AsyncSocketConnectTimeoutError,
  22. AsyncSocketReadMaxedOutError, // Reached set maxLength without completing
  23. AsyncSocketReadTimeoutError,
  24. AsyncSocketWriteTimeoutError
  25. };
  26. typedef enum AsyncSocketError AsyncSocketError;
  27. @interface NSObject (AsyncSocketDelegate)
  28. /**
  29. * In the event of an error, the socket is closed.
  30. * You may call "unreadData" during this call-back to get the last bit of data off the socket.
  31. * When connecting, this delegate method may be called
  32. * before"onSocket:didAcceptNewSocket:" or "onSocket:didConnectToHost:".
  33. **/
  34. - (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err;
  35. /**
  36. * Called when a socket disconnects with or without error. If you want to release a socket after it disconnects,
  37. * do so here. It is not safe to do that during "onSocket:willDisconnectWithError:".
  38. *
  39. * If you call the disconnect method, and the socket wasn't already disconnected,
  40. * this delegate method will be called before the disconnect method returns.
  41. **/
  42. - (void)onSocketDidDisconnect:(AsyncSocket *)sock;
  43. /**
  44. * Called when a socket accepts a connection. Another socket is spawned to handle it. The new socket will have
  45. * the same delegate and will call "onSocket:didConnectToHost:port:".
  46. **/
  47. - (void)onSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket;
  48. /**
  49. * Called when a new socket is spawned to handle a connection. This method should return the run-loop of the
  50. * thread on which the new socket and its delegate should operate. If omitted, [NSRunLoop currentRunLoop] is used.
  51. **/
  52. - (NSRunLoop *)onSocket:(AsyncSocket *)sock wantsRunLoopForNewSocket:(AsyncSocket *)newSocket;
  53. /**
  54. * Called when a socket is about to connect. This method should return YES to continue, or NO to abort.
  55. * If aborted, will result in AsyncSocketCanceledError.
  56. *
  57. * If the connectToHost:onPort:error: method was called, the delegate will be able to access and configure the
  58. * CFReadStream and CFWriteStream as desired prior to connection.
  59. *
  60. * If the connectToAddress:error: method was called, the delegate will be able to access and configure the
  61. * CFSocket and CFSocketNativeHandle (BSD socket) as desired prior to connection. You will be able to access and
  62. * configure the CFReadStream and CFWriteStream in the onSocket:didConnectToHost:port: method.
  63. **/
  64. - (BOOL)onSocketWillConnect:(AsyncSocket *)sock;
  65. /**
  66. * Called when a socket connects and is ready for reading and writing.
  67. * The host parameter will be an IP address, not a DNS name.
  68. **/
  69. - (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port;
  70. /**
  71. * Called when a socket has completed reading the requested data into memory.
  72. * Not called if there is an error.
  73. **/
  74. - (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag;
  75. /**
  76. * Called when a socket has read in data, but has not yet completed the read.
  77. * This would occur if using readToData: or readToLength: methods.
  78. * It may be used to for things such as updating progress bars.
  79. **/
  80. - (void)onSocket:(AsyncSocket *)sock didReadPartialDataOfLength:(CFIndex)partialLength tag:(long)tag;
  81. /**
  82. * Called when a socket has completed writing the requested data. Not called if there is an error.
  83. **/
  84. - (void)onSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag;
  85. /**
  86. * Called when a socket has written some data, but has not yet completed the entire write.
  87. * It may be used to for things such as updating progress bars.
  88. **/
  89. - (void)onSocket:(AsyncSocket *)sock didWritePartialDataOfLength:(CFIndex)partialLength tag:(long)tag;
  90. /**
  91. * Called if a read operation has reached its timeout without completing.
  92. * This method allows you to optionally extend the timeout.
  93. * If you return a positive time interval (> 0) the read's timeout will be extended by the given amount.
  94. * If you don't implement this method, or return a non-positive time interval (<= 0) the read will timeout as usual.
  95. *
  96. * The elapsed parameter is the sum of the original timeout, plus any additions previously added via this method.
  97. * The length parameter is the number of bytes that have been read so far for the read operation.
  98. *
  99. * Note that this method may be called multiple times for a single read if you return positive numbers.
  100. **/
  101. - (NSTimeInterval)onSocket:(AsyncSocket *)sock
  102. shouldTimeoutReadWithTag:(long)tag
  103. elapsed:(NSTimeInterval)elapsed
  104. bytesDone:(CFIndex)length;
  105. /**
  106. * Called if a write operation has reached its timeout without completing.
  107. * This method allows you to optionally extend the timeout.
  108. * If you return a positive time interval (> 0) the write's timeout will be extended by the given amount.
  109. * If you don't implement this method, or return a non-positive time interval (<= 0) the write will timeout as usual.
  110. *
  111. * The elapsed parameter is the sum of the original timeout, plus any additions previously added via this method.
  112. * The length parameter is the number of bytes that have been written so far for the write operation.
  113. *
  114. * Note that this method may be called multiple times for a single write if you return positive numbers.
  115. **/
  116. - (NSTimeInterval)onSocket:(AsyncSocket *)sock
  117. shouldTimeoutWriteWithTag:(long)tag
  118. elapsed:(NSTimeInterval)elapsed
  119. bytesDone:(CFIndex)length;
  120. /**
  121. * Called after the socket has successfully completed SSL/TLS negotiation.
  122. * This method is not called unless you use the provided startTLS method.
  123. *
  124. * If a SSL/TLS negotiation fails (invalid certificate, etc) then the socket will immediately close,
  125. * and the onSocket:willDisconnectWithError: delegate method will be called with the specific SSL error code.
  126. **/
  127. - (void)onSocketDidSecure:(AsyncSocket *)sock;
  128. @end
  129. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  130. #pragma mark -
  131. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  132. @interface AsyncSocket : NSObject
  133. {
  134. CFSocketNativeHandle theNativeSocket4;
  135. CFSocketNativeHandle theNativeSocket6;
  136. CFSocketRef theSocket4; // IPv4 accept or connect socket
  137. CFSocketRef theSocket6; // IPv6 accept or connect socket
  138. CFReadStreamRef theReadStream;
  139. CFWriteStreamRef theWriteStream;
  140. CFRunLoopSourceRef theSource4; // For theSocket4
  141. CFRunLoopSourceRef theSource6; // For theSocket6
  142. CFRunLoopRef theRunLoop;
  143. CFSocketContext theContext;
  144. NSArray *theRunLoopModes;
  145. NSTimer *theConnectTimer;
  146. NSMutableArray *theReadQueue;
  147. AsyncReadPacket *theCurrentRead;
  148. NSTimer *theReadTimer;
  149. NSMutableData *partialReadBuffer;
  150. NSMutableArray *theWriteQueue;
  151. AsyncWritePacket *theCurrentWrite;
  152. NSTimer *theWriteTimer;
  153. id theDelegate;
  154. UInt16 theFlags;
  155. long theUserData;
  156. }
  157. - (id)init;
  158. - (id)initWithDelegate:(id)delegate;
  159. - (id)initWithDelegate:(id)delegate userData:(long)userData;
  160. /* String representation is long but has no "\n". */
  161. - (NSString *)description;
  162. /**
  163. * Use "canSafelySetDelegate" to see if there is any pending business (reads and writes) with the current delegate
  164. * before changing it. It is, of course, safe to change the delegate before connecting or accepting connections.
  165. **/
  166. - (id)delegate;
  167. - (BOOL)canSafelySetDelegate;
  168. - (void)setDelegate:(id)delegate;
  169. /* User data can be a long, or an id or void * cast to a long. */
  170. - (long)userData;
  171. - (void)setUserData:(long)userData;
  172. /* Don't use these to read or write. And don't close them either! */
  173. - (CFSocketRef)getCFSocket;
  174. - (CFReadStreamRef)getCFReadStream;
  175. - (CFWriteStreamRef)getCFWriteStream;
  176. // Once one of the accept or connect methods are called, the AsyncSocket instance is locked in
  177. // and the other accept/connect methods can't be called without disconnecting the socket first.
  178. // If the attempt fails or times out, these methods either return NO or
  179. // call "onSocket:willDisconnectWithError:" and "onSockedDidDisconnect:".
  180. // When an incoming connection is accepted, AsyncSocket invokes several delegate methods.
  181. // These methods are (in chronological order):
  182. // 1. onSocket:didAcceptNewSocket:
  183. // 2. onSocket:wantsRunLoopForNewSocket:
  184. // 3. onSocketWillConnect:
  185. //
  186. // Your server code will need to retain the accepted socket (if you want to accept it).
  187. // The best place to do this is probably in the onSocket:didAcceptNewSocket: method.
  188. //
  189. // After the read and write streams have been setup for the newly accepted socket,
  190. // the onSocket:didConnectToHost:port: method will be called on the proper run loop.
  191. //
  192. // Multithreading Note: If you're going to be moving the newly accepted socket to another run
  193. // loop by implementing onSocket:wantsRunLoopForNewSocket:, then you should wait until the
  194. // onSocket:didConnectToHost:port: method before calling read, write, or startTLS methods.
  195. // Otherwise read/write events are scheduled on the incorrect runloop, and chaos may ensue.
  196. /**
  197. * Tells the socket to begin listening and accepting connections on the given port.
  198. * When a connection comes in, the AsyncSocket instance will call the various delegate methods (see above).
  199. * The socket will listen on all available interfaces (e.g. wifi, ethernet, etc)
  200. **/
  201. - (BOOL)acceptOnPort:(UInt16)port error:(NSError **)errPtr;
  202. /**
  203. * This method is the same as acceptOnPort:error: with the additional option
  204. * of specifying which interface to listen on. So, for example, if you were writing code for a server that
  205. * has multiple IP addresses, you could specify which address you wanted to listen on. Or you could use it
  206. * to specify that the socket should only accept connections over ethernet, and not other interfaces such as wifi.
  207. * You may also use the special strings "localhost" or "loopback" to specify that
  208. * the socket only accept connections from the local machine.
  209. *
  210. * To accept connections on any interface pass nil, or simply use the acceptOnPort:error: method.
  211. **/
  212. - (BOOL)acceptOnInterface:(NSString *)interface port:(UInt16)port error:(NSError **)errPtr;
  213. /**
  214. * Connects to the given host and port.
  215. * The host may be a domain name (e.g. "deusty.com") or an IP address string (e.g. "192.168.0.2")
  216. **/
  217. - (BOOL)connectToHost:(NSString *)hostname onPort:(UInt16)port error:(NSError **)errPtr;
  218. /**
  219. * This method is the same as connectToHost:onPort:error: with an additional timeout option.
  220. * To not time out use a negative time interval, or simply use the connectToHost:onPort:error: method.
  221. **/
  222. - (BOOL)connectToHost:(NSString *)hostname
  223. onPort:(UInt16)port
  224. withTimeout:(NSTimeInterval)timeout
  225. error:(NSError **)errPtr;
  226. /**
  227. * Connects to the given address, specified as a sockaddr structure wrapped in a NSData object.
  228. * For example, a NSData object returned from NSNetservice's addresses method.
  229. *
  230. * If you have an existing struct sockaddr you can convert it to a NSData object like so:
  231. * struct sockaddr sa -> NSData *dsa = [NSData dataWithBytes:&remoteAddr length:remoteAddr.sa_len];
  232. * struct sockaddr *sa -> NSData *dsa = [NSData dataWithBytes:remoteAddr length:remoteAddr->sa_len];
  233. **/
  234. - (BOOL)connectToAddress:(NSData *)remoteAddr error:(NSError **)errPtr;
  235. /**
  236. * This method is the same as connectToAddress:error: with an additional timeout option.
  237. * To not time out use a negative time interval, or simply use the connectToAddress:error: method.
  238. **/
  239. - (BOOL)connectToAddress:(NSData *)remoteAddr withTimeout:(NSTimeInterval)timeout error:(NSError **)errPtr;
  240. /**
  241. * Disconnects immediately. Any pending reads or writes are dropped.
  242. * If the socket is not already disconnected, the onSocketDidDisconnect delegate method
  243. * will be called immediately, before this method returns.
  244. *
  245. * Please note the recommended way of releasing an AsyncSocket instance (e.g. in a dealloc method)
  246. * [asyncSocket setDelegate:nil];
  247. * [asyncSocket disconnect];
  248. * [asyncSocket release];
  249. **/
  250. - (void)disconnect;
  251. /**
  252. * Disconnects after all pending reads have completed.
  253. * After calling this, the read and write methods will do nothing.
  254. * The socket will disconnect even if there are still pending writes.
  255. **/
  256. - (void)disconnectAfterReading;
  257. /**
  258. * Disconnects after all pending writes have completed.
  259. * After calling this, the read and write methods will do nothing.
  260. * The socket will disconnect even if there are still pending reads.
  261. **/
  262. - (void)disconnectAfterWriting;
  263. /**
  264. * Disconnects after all pending reads and writes have completed.
  265. * After calling this, the read and write methods will do nothing.
  266. **/
  267. - (void)disconnectAfterReadingAndWriting;
  268. /* Returns YES if the socket and streams are open, connected, and ready for reading and writing. */
  269. - (BOOL)isConnected;
  270. /**
  271. * Returns the local or remote host and port to which this socket is connected, or nil and 0 if not connected.
  272. * The host will be an IP address.
  273. **/
  274. - (NSString *)connectedHost;
  275. - (UInt16)connectedPort;
  276. - (NSString *)localHost;
  277. - (UInt16)localPort;
  278. /**
  279. * Returns the local or remote address to which this socket is connected,
  280. * specified as a sockaddr structure wrapped in a NSData object.
  281. *
  282. * See also the connectedHost, connectedPort, localHost and localPort methods.
  283. **/
  284. - (NSData *)connectedAddress;
  285. - (NSData *)localAddress;
  286. /**
  287. * Returns whether the socket is IPv4 or IPv6.
  288. * An accepting socket may be both.
  289. **/
  290. - (BOOL)isIPv4;
  291. - (BOOL)isIPv6;
  292. // The readData and writeData methods won't block.
  293. //
  294. // You may optionally set a timeout for any read/write operation. (To not timeout, use a negative time interval.)
  295. // If a read/write opertion times out, the corresponding "onSocket:shouldTimeout..." delegate method
  296. // is called to optionally allow you to extend the timeout.
  297. // Upon a timeout, the "onSocket:willDisconnectWithError:" method is called, followed by "onSocketDidDisconnect".
  298. //
  299. // The tag is for your convenience.
  300. // You can use it as an array index, step number, state id, pointer, etc., just like the socket's user data.
  301. /**
  302. * This will read a certain number of bytes into memory, and call the delegate method when those bytes have been read.
  303. *
  304. * If the length is 0, this method does nothing and the delegate is not called.
  305. * If the timeout value is negative, the read operation will not use a timeout.
  306. **/
  307. - (void)readDataToLength:(CFIndex)length withTimeout:(NSTimeInterval)timeout tag:(long)tag;
  308. /**
  309. * This reads bytes until (and including) the passed "data" parameter, which acts as a separator.
  310. * The bytes and the separator are returned by the delegate method.
  311. *
  312. * If you pass nil or zero-length data as the "data" parameter,
  313. * the method will do nothing, and the delegate will not be called.
  314. * If the timeout value is negative, the read operation will not use a timeout.
  315. *
  316. * To read a line from the socket, use the line separator (e.g. CRLF for HTTP, see below) as the "data" parameter.
  317. * Note that this method is not character-set aware, so if a separator can occur naturally as part of the encoding for
  318. * a character, the read will prematurely end.
  319. **/
  320. - (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;
  321. /**
  322. * Same as readDataToData:withTimeout:tag, with the additional restriction that the amount of data read
  323. * may not surpass the given maxLength (specified in bytes).
  324. *
  325. * If you pass a maxLength parameter that is less than the length of the data parameter,
  326. * the method will do nothing, and the delegate will not be called.
  327. *
  328. * If the max length is surpassed, it is treated the same as a timeout - the socket is closed.
  329. *
  330. * Pass -1 as maxLength if no length restriction is desired, or simply use the readDataToData:withTimeout:tag method.
  331. **/
  332. - (void)readDataToData:(NSData *)data withTimeout:(NSTimeInterval)timeout maxLength:(CFIndex)length tag:(long)tag;
  333. /**
  334. * Reads the first available bytes that become available on the socket.
  335. *
  336. * If the timeout value is negative, the read operation will not use a timeout.
  337. **/
  338. - (void)readDataWithTimeout:(NSTimeInterval)timeout tag:(long)tag;
  339. /**
  340. * Writes data to the socket, and calls the delegate when finished.
  341. *
  342. * If you pass in nil or zero-length data, this method does nothing and the delegate will not be called.
  343. * If the timeout value is negative, the write operation will not use a timeout.
  344. **/
  345. - (void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;
  346. /**
  347. * Returns progress of current read or write, from 0.0 to 1.0, or NaN if no read/write (use isnan() to check).
  348. * "tag", "done" and "total" will be filled in if they aren't NULL.
  349. **/
  350. - (float)progressOfReadReturningTag:(long *)tag bytesDone:(CFIndex *)done total:(CFIndex *)total;
  351. - (float)progressOfWriteReturningTag:(long *)tag bytesDone:(CFIndex *)done total:(CFIndex *)total;
  352. /**
  353. * Secures the connection using SSL/TLS.
  354. *
  355. * This method may be called at any time, and the TLS handshake will occur after all pending reads and writes
  356. * are finished. This allows one the option of sending a protocol dependent StartTLS message, and queuing
  357. * the upgrade to TLS at the same time, without having to wait for the write to finish.
  358. * Any reads or writes scheduled after this method is called will occur over the secured connection.
  359. *
  360. * The possible keys and values for the TLS settings are well documented.
  361. * Some possible keys are:
  362. * - kCFStreamSSLLevel
  363. * - kCFStreamSSLAllowsExpiredCertificates
  364. * - kCFStreamSSLAllowsExpiredRoots
  365. * - kCFStreamSSLAllowsAnyRoot
  366. * - kCFStreamSSLValidatesCertificateChain
  367. * - kCFStreamSSLPeerName
  368. * - kCFStreamSSLCertificates
  369. * - kCFStreamSSLIsServer
  370. *
  371. * Please refer to Apple's documentation for associated values, as well as other possible keys.
  372. *
  373. * If you pass in nil or an empty dictionary, the default settings will be used.
  374. *
  375. * The default settings will check to make sure the remote party's certificate is signed by a
  376. * trusted 3rd party certificate agency (e.g. verisign) and that the certificate is not expired.
  377. * However it will not verify the name on the certificate unless you
  378. * give it a name to verify against via the kCFStreamSSLPeerName key.
  379. * The security implications of this are important to understand.
  380. * Imagine you are attempting to create a secure connection to MySecureServer.com,
  381. * but your socket gets directed to MaliciousServer.com because of a hacked DNS server.
  382. * If you simply use the default settings, and MaliciousServer.com has a valid certificate,
  383. * the default settings will not detect any problems since the certificate is valid.
  384. * To properly secure your connection in this particular scenario you
  385. * should set the kCFStreamSSLPeerName property to "MySecureServer.com".
  386. * If you do not know the peer name of the remote host in advance (for example, you're not sure
  387. * if it will be "domain.com" or "www.domain.com"), then you can use the default settings to validate the
  388. * certificate, and then use the X509Certificate class to verify the issuer after the socket has been secured.
  389. * The X509Certificate class is part of the CocoaAsyncSocket open source project.
  390. **/
  391. - (void)startTLS:(NSDictionary *)tlsSettings;
  392. /**
  393. * For handling readDataToData requests, data is necessarily read from the socket in small increments.
  394. * The performance can be much improved by allowing AsyncSocket to read larger chunks at a time and
  395. * store any overflow in a small internal buffer.
  396. * This is termed pre-buffering, as some data may be read for you before you ask for it.
  397. * If you use readDataToData a lot, enabling pre-buffering will result in better performance, especially on the iPhone.
  398. *
  399. * The default pre-buffering state is controlled by the DEFAULT_PREBUFFERING definition.
  400. * It is highly recommended one leave this set to YES.
  401. *
  402. * This method exists in case pre-buffering needs to be disabled by default for some unforeseen reason.
  403. * In that case, this method exists to allow one to easily enable pre-buffering when ready.
  404. **/
  405. - (void)enablePreBuffering;
  406. /**
  407. * When you create an AsyncSocket, it is added to the runloop of the current thread.
  408. * So for manually created sockets, it is easiest to simply create the socket on the thread you intend to use it.
  409. *
  410. * If a new socket is accepted, the delegate method onSocket:wantsRunLoopForNewSocket: is called to
  411. * allow you to place the socket on a separate thread. This works best in conjunction with a thread pool design.
  412. *
  413. * If, however, you need to move the socket to a separate thread at a later time, this
  414. * method may be used to accomplish the task.
  415. *
  416. * This method must be called from the thread/runloop the socket is currently running on.
  417. *
  418. * Note: After calling this method, all further method calls to this object should be done from the given runloop.
  419. * Also, all delegate calls will be sent on the given runloop.
  420. **/
  421. - (BOOL)moveToRunLoop:(NSRunLoop *)runLoop;
  422. /**
  423. * Allows you to configure which run loop modes the socket uses.
  424. * The default set of run loop modes is NSDefaultRunLoopMode.
  425. *
  426. * If you'd like your socket to continue operation during other modes, you may want to add modes such as
  427. * NSModalPanelRunLoopMode or NSEventTrackingRunLoopMode. Or you may simply want to use NSRunLoopCommonModes.
  428. *
  429. * Accepted sockets will automatically inherit the same run loop modes as the listening socket.
  430. *
  431. * Note: NSRunLoopCommonModes is defined in 10.5. For previous versions one can use kCFRunLoopCommonModes.
  432. **/
  433. - (BOOL)setRunLoopModes:(NSArray *)runLoopModes;
  434. /**
  435. * Returns the current run loop modes the AsyncSocket instance is operating in.
  436. * The default set of run loop modes is NSDefaultRunLoopMode.
  437. **/
  438. - (NSArray *)runLoopModes;
  439. /**
  440. * In the event of an error, this method may be called during onSocket:willDisconnectWithError: to read
  441. * any data that's left on the socket.
  442. **/
  443. - (NSData *)unreadData;
  444. /* A few common line separators, for use with the readDataToData:... methods. */
  445. + (NSData *)CRLFData; // 0x0D0A
  446. + (NSData *)CRData; // 0x0D
  447. + (NSData *)LFData; // 0x0A
  448. + (NSData *)ZeroData; // 0x00
  449. + (NSData *)JsonData;
  450. @end