Skip to content

Commit

Permalink
Merge pull request #510 from Simperium/develop
Browse files Browse the repository at this point in the history
Simperium Mark 0.8.4
  • Loading branch information
jleandroperez committed Sep 16, 2015
2 parents b4c3925 + 8c3407a commit 3d53ad7
Show file tree
Hide file tree
Showing 19 changed files with 367 additions and 668 deletions.
8 changes: 6 additions & 2 deletions External/SPReachability/SPReachability.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ + (instancetype)reachabilityWithHostName:(NSString *)hostName
{
returnValue->_reachabilityRef = reachability;
returnValue->_alwaysReturnLocalWiFiStatus = NO;
}
} else {
CFRelease(reachability);
}
}
return returnValue;
}
Expand All @@ -137,7 +139,9 @@ + (instancetype)reachabilityWithAddress:(const struct sockaddr_in *)hostAddress
{
returnValue->_reachabilityRef = reachability;
returnValue->_alwaysReturnLocalWiFiStatus = NO;
}
} else {
CFRelease(reachability);
}
}
return returnValue;
}
Expand Down
8 changes: 4 additions & 4 deletions External/SocketRocket/SPRWebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
#import <Foundation/Foundation.h>
#import <Security/SecCertificate.h>

typedef enum {
typedef NS_ENUM(NSInteger, SPRReadyState) {
SPR_CONNECTING = 0,
SPR_OPEN = 1,
SPR_CLOSING = 2,
SPR_CLOSED = 3,
} SPRReadyState;
};

typedef enum SPRStatusCode : NSInteger {
typedef NS_ENUM(NSInteger, SPRStatusCode) {
SPRStatusCodeNormal = 1000,
SPRStatusCodeGoingAway = 1001,
SPRStatusCodeProtocolError = 1002,
Expand All @@ -35,7 +35,7 @@ typedef enum SPRStatusCode : NSInteger {
SPRStatusCodeInvalidUTF8 = 1007,
SPRStatusCodePolicyViolated = 1008,
SPRStatusCodeMessageTooBig = 1009,
} SPRStatusCode;
};

@class SPRWebSocket;

Expand Down
65 changes: 26 additions & 39 deletions External/SocketRocket/SPRWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,33 +178,6 @@ - (void)returnConsumer:(SPRIOConsumer *)consumer;

@interface SPRWebSocket () <NSStreamDelegate>

- (void)_writeData:(NSData *)data;
- (void)_closeWithProtocolError:(NSString *)message;
- (void)_failWithError:(NSError *)error;

- (void)_disconnect;

- (void)_readFrameNew;
- (void)_readFrameContinue;

- (void)_pumpScanner;

- (void)_pumpWriting;

- (void)_addConsumerWithScanner:(stream_scanner)consumer callback:(data_callback)callback;
- (void)_addConsumerWithDataLength:(size_t)dataLength callback:(data_callback)callback readToCurrentFrame:(BOOL)readToCurrentFrame unmaskBytes:(BOOL)unmaskBytes;
- (void)_addConsumerWithScanner:(stream_scanner)consumer callback:(data_callback)callback dataLength:(size_t)dataLength;
- (void)_readUntilBytes:(const void *)bytes length:(size_t)length callback:(data_callback)dataHandler;
- (void)_readUntilHeaderCompleteWithCallback:(data_callback)dataHandler;

- (void)_sendFrameWithOpcode:(SROpCode)opcode data:(id)data;

- (BOOL)_checkHandshake:(CFHTTPMessageRef)httpMessage;
- (void)_SR_commonInit;

- (void)_initializeStreams;
- (void)_connect;

@property (nonatomic) SPRReadyState readyState;

@property (nonatomic) NSOperationQueue *delegateOperationQueue;
Expand Down Expand Up @@ -402,7 +375,7 @@ - (void)open;

_selfRetain = self;

[self _connect];
[self openConnection];
}

// Calls block on delegate queue
Expand Down Expand Up @@ -591,7 +564,7 @@ - (void)_initializeStreams;
_outputStream.delegate = self;
}

- (void)_connect;
- (void)openConnection;
{
if (!_scheduledRunloops.count) {
[self scheduleInRunLoop:[NSRunLoop SPR_networkRunLoop] forMode:NSDefaultRunLoopMode];
Expand Down Expand Up @@ -638,7 +611,7 @@ - (void)closeWithCode:(NSInteger)code reason:(NSString *)reason;
SRFastLog(@"Closing with code %d reason %@", code, reason);

if (wasConnecting) {
[self _disconnect];
[self closeConnection];
return;
}

Expand Down Expand Up @@ -675,7 +648,7 @@ - (void)_closeWithProtocolError:(NSString *)message;
[self _performDelegateBlock:^{
[self closeWithCode:SPRStatusCodeProtocolError reason:message];
dispatch_async(_workQueue, ^{
[self _disconnect];
[self closeConnection];
});
}];
}
Expand All @@ -695,7 +668,7 @@ - (void)_failWithError:(NSError *)error;

SRFastLog(@"Failing with error %@", error.localizedDescription);

[self _disconnect];
[self closeConnection];
[self _scheduleCleanup];
}
});
Expand Down Expand Up @@ -838,11 +811,11 @@ - (void)handleCloseWithData:(NSData *)data;
[self closeWithCode:1000 reason:nil];
}
dispatch_async(_workQueue, ^{
[self _disconnect];
[self closeConnection];
});
}

- (void)_disconnect;
- (void)closeConnection;
{
[self assertOnWorkQueue];
SRFastLog(@"Trying to disconnect");
Expand All @@ -869,7 +842,7 @@ - (void)_handleFrameWithData:(NSData *)frameData opCode:(NSInteger)opcode;
if (str == nil && frameData) {
[self closeWithCode:SPRStatusCodeInvalidUTF8 reason:@"Text frames must be valid UTF-8"];
dispatch_async(_workQueue, ^{
[self _disconnect];
[self closeConnection];
});

return;
Expand Down Expand Up @@ -1297,7 +1270,7 @@ - (BOOL)_innerPumpScanner {
if (valid_utf8_size == -1) {
[self closeWithCode:SPRStatusCodeInvalidUTF8 reason:@"Text frames must be valid UTF-8"];
dispatch_async(_workQueue, ^{
[self _disconnect];
[self closeConnection];
});
return didWork;
} else {
Expand Down Expand Up @@ -1784,7 +1757,7 @@ - (void)dealloc
sr_dispatch_release(_waitGroup);
}

- (id)init
- (instancetype)init
{
self = [super init];
if (self) {
Expand All @@ -1800,8 +1773,22 @@ - (void)main;
_runLoop = [NSRunLoop currentRunLoop];
dispatch_group_leave(_waitGroup);

NSTimer *timer = [[NSTimer alloc] initWithFireDate:[NSDate distantFuture] interval:0.0 target:nil selector:nil userInfo:nil repeats:NO];
[_runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
// Add an empty run loop source to prevent runloop from spinning.
CFRunLoopSourceContext sourceCtx = {
.version = 0,
.info = NULL,
.retain = NULL,
.release = NULL,
.copyDescription = NULL,
.equal = NULL,
.hash = NULL,
.schedule = NULL,
.cancel = NULL,
.perform = NULL
};
CFRunLoopSourceRef source = CFRunLoopSourceCreate(NULL, 0, &sourceCtx);
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopDefaultMode);
CFRelease(source);

while ([_runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.automattic.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
Expand Down

0 comments on commit 3d53ad7

Please sign in to comment.