Skip to content
Browse files

Fix secure connections.

  • Loading branch information...
1 parent 3a623dd commit 16d9bc43a619a65537f7f591fee0c9f195a214e2 @pk committed
Showing with 14 additions and 18 deletions.
  1. +4 −6 PKWebSocket/Handlers/PKWebSocketHandler.m
  2. +10 −12 PKWebSocketTests/PKWebSocketTests.m
View
10 PKWebSocket/Handlers/PKWebSocketHandler.m
@@ -67,6 +67,7 @@ - (void)setStatus:(PKWebSocketStatus)aStatus {
- (BOOL)connectWithURL:(PKWebSocketURL *)anURL error:(NSError **)outError {
if (self.status != PKWebSocketDisconnectedStatus) return YES;
+ self->_url = anURL;
self.status = PKWebSocketConnectingStatus;
if ([anURL isSecure] && self.tlsSettings != nil) {
@@ -78,7 +79,6 @@ - (BOOL)connectWithURL:(PKWebSocketURL *)anURL error:(NSError **)outError {
withTimeout:self.timeout
error:outError];
if (status) {
- self->_url = anURL;
if (self.runLoopModes) {
[self.socket setRunLoopModes:self.runLoopModes];
}
@@ -163,12 +163,10 @@ - (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UIn
}
- (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)outError {
- if (self.status == PKWebSocketOpenedStatus) {
- self.status = PKWebSocketClosedStatus;
- } else {
- NSLog(@"");
- //[self.delegate _dispatchFailure:[NSNumber numberWithInt:1]];
+ if (self.status != PKWebSocketOpenedStatus) {
+ [self.delegate handler:self didFailWithError:outError];
}
+ self.status = PKWebSocketClosedStatus;
}
- (void)onSocketDidDisconnect:(AsyncSocket *)sock {
View
22 PKWebSocketTests/PKWebSocketTests.m
@@ -61,19 +61,18 @@ - (void)webSocket:(PKWebSocket *)webSocket didReceiveMessage:(PKWebSocketMessage
}
-- (void)testTestStandardConnectionShouldBeSuccessful {
+- (void)testStandardConnectionShouldBeSuccessful {
NSError *error;
PKWebSocket *ws = [[PKWebSocket alloc] initWithHandler:_handler delegate:self];
STAssertTrue([ws openWithURLString:[self standardURL] error:&error],nil);
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
- // Begin a run loop terminated when the downloadComplete it set to true
- NSDate *date = [[NSDate date] dateByAddingTimeInterval:6];
+ // Begin a run loop terminated when the finished it set to true
+ NSDate *date = [[NSDate date] dateByAddingTimeInterval:1];
while (!_finished && [theRL runMode:NSDefaultRunLoopMode beforeDate:date]);
}
-/*
-- (void)testTestSecureConnectionShouldBeSuccessful {
+- (void)testSecureConnectionShouldBeSuccessful {
NSMutableDictionary *tlsSettings = [NSMutableDictionary dictionaryWithCapacity:4];
[tlsSettings setObject:@"echo.websocket.org" forKey:(NSString *)kCFStreamSSLPeerName];
@@ -90,17 +89,16 @@ - (void)testTestSecureConnectionShouldBeSuccessful {
forKey:(NSString *)kCFStreamSSLValidatesCertificateChain];
NSError *error;
- PKWebSocket *ws = [[PKWebSocket alloc] initWithURLString:[self secureURL]
- handler:_handler
- delegate:self];
+ PKWebSocket *ws = [[PKWebSocket alloc] initWithHandler:_handler
+ delegate:self];
[ws setTLSSettings:tlsSettings];
- STAssertTrue([ws openWithError:&error],nil);
+ STAssertTrue([ws openWithURLString:[self secureURL] error:&error],nil);
NSRunLoop *theRL = [NSRunLoop currentRunLoop];
- // Begin a run loop terminated when the downloadComplete it set to true
- NSDate *date = [[NSDate date] dateByAddingTimeInterval:15];
+ // Begin a run loop terminated when the finished it set to true
+ NSDate *date = [[NSDate date] dateByAddingTimeInterval:1];
while (!_finished && [theRL runMode:NSDefaultRunLoopMode beforeDate:date]);
}
-*/
+
@end

0 comments on commit 16d9bc4

Please sign in to comment.
Something went wrong with that request. Please try again.