|
42 | 42 | static NSString* kSecureHandshakePortURL = @"https://%@:%d/socket.io/1/?t=%d%@";
|
43 | 43 | static NSString* kSecureHandshakeURL = @"https://%@/socket.io/1/?t=%d%@";
|
44 | 44 |
|
| 45 | +float const defaultConnectionTimeout = 10.0f; |
| 46 | + |
45 | 47 | NSString* const SocketIOError = @"SocketIOError";
|
46 | 48 | NSString* const SocketIOException = @"SocketIOException";
|
47 | 49 |
|
@@ -95,15 +97,27 @@ - (id) initWithDelegate:(id<SocketIODelegate>)delegate
|
95 | 97 |
|
96 | 98 | - (void) connectToHost:(NSString *)host onPort:(NSInteger)port
|
97 | 99 | {
|
98 |
| - [self connectToHost:host onPort:port withParams:nil withNamespace:@""]; |
| 100 | + [self connectToHost:host onPort:port withParams:nil withNamespace:@"" withConnectionTimeout:defaultConnectionTimeout]; |
99 | 101 | }
|
100 | 102 |
|
101 | 103 | - (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params
|
102 | 104 | {
|
103 |
| - [self connectToHost:host onPort:port withParams:params withNamespace:@""]; |
| 105 | + [self connectToHost:host onPort:port withParams:params withNamespace:@"" withConnectionTimeout:defaultConnectionTimeout]; |
| 106 | +} |
| 107 | + |
| 108 | +- (void) connectToHost:(NSString *)host |
| 109 | + onPort:(NSInteger)port |
| 110 | + withParams:(NSDictionary *)params |
| 111 | + withNamespace:(NSString *)endpoint |
| 112 | +{ |
| 113 | + [self connectToHost:host onPort:port withParams:params withNamespace:@"" withConnectionTimeout:defaultConnectionTimeout]; |
104 | 114 | }
|
105 | 115 |
|
106 |
| -- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint |
| 116 | +- (void) connectToHost:(NSString *)host |
| 117 | + onPort:(NSInteger)port |
| 118 | + withParams:(NSDictionary *)params |
| 119 | + withNamespace:(NSString *)endpoint |
| 120 | + withConnectionTimeout:(NSTimeInterval)connectionTimeout |
107 | 121 | {
|
108 | 122 | if (!_isConnected && !_isConnecting) {
|
109 | 123 | _isConnecting = YES;
|
@@ -138,7 +152,7 @@ - (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDic
|
138 | 152 | // make a request
|
139 | 153 | NSURLRequest *request = [NSURLRequest requestWithURL:url
|
140 | 154 | cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
|
141 |
| - timeoutInterval:10.0]; |
| 155 | + timeoutInterval:connectionTimeout]; |
142 | 156 |
|
143 | 157 | _handshake = [[NSURLConnection alloc] initWithRequest:request
|
144 | 158 | delegate:self startImmediately:NO];
|
@@ -178,7 +192,7 @@ - (void) disconnectForced
|
178 | 192 |
|
179 | 193 | [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
|
180 | 194 |
|
181 |
| - if(error || [response statusCode] != 200) { |
| 195 | + if (error || [response statusCode] != 200) { |
182 | 196 | DEBUGLOG(@"Error during disconnect: %@", error);
|
183 | 197 | }
|
184 | 198 |
|
@@ -268,7 +282,7 @@ - (void) sendHeartbeat
|
268 | 282 |
|
269 | 283 | - (void) send:(SocketIOPacket *)packet
|
270 | 284 | {
|
271 |
| - if(![self isConnected] && ![self isConnecting]) { |
| 285 | + if (![self isConnected] && ![self isConnecting]) { |
272 | 286 | DEBUGLOG(@"Already disconnected!");
|
273 | 287 | return;
|
274 | 288 | }
|
|
0 commit comments