Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Error reporting for the socket opening.

  • Loading branch information...
commit 695e97856fb5157db6cd543143e08687e2d3e8c0 1 parent ce91d22
Pavel Kunc authored April 19, 2012
2  PKWebSocket/PKWebSocket.h
@@ -35,7 +35,7 @@ enum {
35 35
                 handler:(PKWebSocketHandler *)handler
36 36
                delegate:(id<PKWebSocketDelegate>)delegate;
37 37
 
38  
-- (void)open;
  38
+- (BOOL)openWithError:(NSError **)outError;
39 39
 - (void)close;
40 40
 - (void)send:(NSString *)message;
41 41
 
24  PKWebSocket/PKWebSocket.m
@@ -72,23 +72,29 @@ - (id)initWithURLString:(NSString *)anURL
72 72
 
73 73
 #pragma mark Public interface
74 74
 
75  
--(void)close {
  75
+- (void)close {
76 76
     [self.socket disconnectAfterReadingAndWriting];
77 77
 }
78 78
 
79  
--(void)open {
  79
+- (BOOL)openWithError:(NSError **)outError {
80 80
     NSAssert(self.handler, @"PKWebSocket: You must set your WebSocket Handler before connecting.");
81 81
 
82  
-    if (self.isConnected) return;
  82
+    if (self.isConnected) return YES;
83 83
 
84 84
     if ([self.url isSecure]) [self.socket startTLS:self.tlsSettings];
85 85
 
86  
-    [self.socket connectToHost:self.url.host
87  
-                        onPort:[self.url.port intValue]
88  
-                   withTimeout:self.timeout
89  
-                         error:nil];
90  
-
91  
-    if (self.runLoopModes) [self.socket setRunLoopModes:self.runLoopModes];
  86
+    NSError *error;
  87
+    BOOL status = [self.socket connectToHost:self.url.host
  88
+                                      onPort:[self.url.port intValue]
  89
+                                 withTimeout:self.timeout
  90
+                                       error:&error];
  91
+    if (status) {
  92
+        if (self.runLoopModes) [self.socket setRunLoopModes:self.runLoopModes];
  93
+        return YES;
  94
+    } else {
  95
+        if (outError != NULL) *outError = error;
  96
+        return NO;
  97
+    }
92 98
 }
93 99
 
94 100
 -(void)send:(NSString *)message {

0 notes on commit 695e978

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