Skip to content

Commit 1abc170

Browse files
committed
Apply patch from Sean McBride. Resolves issue robbiehanson#105. Patch makes the following changes:
- improved const safety by adding some const's where they should have been - fixed a bug where the buffer returned by NSData's bytes method was being mutated. Use NSMutableData instead. - fixed two warnings about casts changing required alignment (-Wcast-align). Use memcpy instead. - fixed another void pointer arithmetic in an iOS-only case - converted all Mac OS style UInt* to standard C99 style uint*_t
1 parent 82a71f1 commit 1abc170

File tree

2 files changed

+109
-113
lines changed

2 files changed

+109
-113
lines changed

GCD/GCDAsyncSocket.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
4343

4444
@interface GCDAsyncSocket : NSObject
4545
{
46-
UInt16 flags;
47-
UInt16 config;
46+
uint16_t flags;
47+
uint16_t config;
4848

4949
id delegate;
5050
dispatch_queue_t delegateQueue;
@@ -191,7 +191,7 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
191191
*
192192
* The socket will listen on all available interfaces (e.g. wifi, ethernet, etc)
193193
**/
194-
- (BOOL)acceptOnPort:(UInt16)port error:(NSError **)errPtr;
194+
- (BOOL)acceptOnPort:(uint16_t)port error:(NSError **)errPtr;
195195

196196
/**
197197
* This method is the same as acceptOnPort:error: with the
@@ -209,7 +209,7 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
209209
*
210210
* To accept connections on any interface pass nil, or simply use the acceptOnPort:error: method.
211211
**/
212-
- (BOOL)acceptOnInterface:(NSString *)interface port:(UInt16)port error:(NSError **)errPtr;
212+
- (BOOL)acceptOnInterface:(NSString *)interface port:(uint16_t)port error:(NSError **)errPtr;
213213

214214
#pragma mark Connecting
215215

@@ -219,15 +219,15 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
219219
* This method invokes connectToHost:onPort:viaInterface:withTimeout:error:
220220
* and uses the default interface, and no timeout.
221221
**/
222-
- (BOOL)connectToHost:(NSString *)host onPort:(UInt16)port error:(NSError **)errPtr;
222+
- (BOOL)connectToHost:(NSString *)host onPort:(uint16_t)port error:(NSError **)errPtr;
223223

224224
/**
225225
* Connects to the given host and port with an optional timeout.
226226
*
227227
* This method invokes connectToHost:onPort:viaInterface:withTimeout:error: and uses the default interface.
228228
**/
229229
- (BOOL)connectToHost:(NSString *)host
230-
onPort:(UInt16)port
230+
onPort:(uint16_t)port
231231
withTimeout:(NSTimeInterval)timeout
232232
error:(NSError **)errPtr;
233233

@@ -261,7 +261,7 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
261261
* This feature is here for networking professionals using very advanced techniques.
262262
**/
263263
- (BOOL)connectToHost:(NSString *)host
264-
onPort:(UInt16)port
264+
onPort:(uint16_t)port
265265
viaInterface:(NSString *)interface
266266
withTimeout:(NSTimeInterval)timeout
267267
error:(NSError **)errPtr;
@@ -376,10 +376,10 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
376376
* The host will be an IP address.
377377
**/
378378
- (NSString *)connectedHost;
379-
- (UInt16)connectedPort;
379+
- (uint16_t)connectedPort;
380380

381381
- (NSString *)localHost;
382-
- (UInt16)localPort;
382+
- (uint16_t)localPort;
383383

384384
/**
385385
* Returns the local or remote address to which this socket is connected,
@@ -728,7 +728,7 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
728728
*
729729
* Example usage:
730730
*
731-
* - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port
731+
* - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
732732
* {
733733
* [asyncSocket performBlock:^{
734734
* [asyncSocket enableBackgroundingOnSocket];
@@ -788,8 +788,8 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
788788
* Extracting host and port information from raw address data.
789789
**/
790790
+ (NSString *)hostFromAddress:(NSData *)address;
791-
+ (UInt16)portFromAddress:(NSData *)address;
792-
+ (BOOL)getHost:(NSString **)hostPtr port:(UInt16 *)portPtr fromAddress:(NSData *)address;
791+
+ (uint16_t)portFromAddress:(NSData *)address;
792+
+ (BOOL)getHost:(NSString **)hostPtr port:(uint16_t *)portPtr fromAddress:(NSData *)address;
793793

794794
/**
795795
* A few common line separators, for use with the readDataToData:... methods.
@@ -844,7 +844,7 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
844844
* Called when a socket connects and is ready for reading and writing.
845845
* The host parameter will be an IP address, not a DNS name.
846846
**/
847-
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port;
847+
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port;
848848

849849
/**
850850
* Called when a socket has completed reading the requested data into memory.

0 commit comments

Comments
 (0)