Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Error reporting for the socket opening.

  • Loading branch information...
commit 695e97856fb5157db6cd543143e08687e2d3e8c0 1 parent ce91d22
@pk authored
Showing with 16 additions and 10 deletions.
  1. +1 −1  PKWebSocket/PKWebSocket.h
  2. +15 −9 PKWebSocket/PKWebSocket.m
View
2  PKWebSocket/PKWebSocket.h
@@ -35,7 +35,7 @@ enum {
handler:(PKWebSocketHandler *)handler
delegate:(id<PKWebSocketDelegate>)delegate;
-- (void)open;
+- (BOOL)openWithError:(NSError **)outError;
- (void)close;
- (void)send:(NSString *)message;
View
24 PKWebSocket/PKWebSocket.m
@@ -72,23 +72,29 @@ - (id)initWithURLString:(NSString *)anURL
#pragma mark Public interface
--(void)close {
+- (void)close {
[self.socket disconnectAfterReadingAndWriting];
}
--(void)open {
+- (BOOL)openWithError:(NSError **)outError {
NSAssert(self.handler, @"PKWebSocket: You must set your WebSocket Handler before connecting.");
- if (self.isConnected) return;
+ if (self.isConnected) return YES;
if ([self.url isSecure]) [self.socket startTLS:self.tlsSettings];
- [self.socket connectToHost:self.url.host
- onPort:[self.url.port intValue]
- withTimeout:self.timeout
- error:nil];
-
- if (self.runLoopModes) [self.socket setRunLoopModes:self.runLoopModes];
+ NSError *error;
+ BOOL status = [self.socket connectToHost:self.url.host
+ onPort:[self.url.port intValue]
+ withTimeout:self.timeout
+ error:&error];
+ if (status) {
+ if (self.runLoopModes) [self.socket setRunLoopModes:self.runLoopModes];
+ return YES;
+ } else {
+ if (outError != NULL) *outError = error;
+ return NO;
+ }
}
-(void)send:(NSString *)message {
Please sign in to comment.
Something went wrong with that request. Please try again.