Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit c1e47f9

Browse files
Add initial connection timeout
1 parent 79fac8e commit c1e47f9

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

SocketIO.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ typedef enum {
107107
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port;
108108
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params;
109109
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint;
110+
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint withConnectionTimeout: (NSTimeInterval) connectionTimeout;
111+
110112
- (void) disconnect;
111113

112114
- (void) sendMessage:(NSString *)data;

SocketIO.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,19 @@ - (id) initWithDelegate:(id<SocketIODelegate>)delegate
9595

9696
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port
9797
{
98-
[self connectToHost:host onPort:port withParams:nil withNamespace:@""];
98+
[self connectToHost:host onPort:port withParams:nil withNamespace:@"" withConnectionTimeout:10.0f];
9999
}
100100

101101
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params
102102
{
103-
[self connectToHost:host onPort:port withParams:params withNamespace:@""];
103+
[self connectToHost:host onPort:port withParams:params withNamespace:@"" withConnectionTimeout:10.0f];
104104
}
105105

106-
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint
106+
- (void)connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint {
107+
[self connectToHost:host onPort:port withParams:params withNamespace:@"" withConnectionTimeout:10.0f];
108+
}
109+
110+
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params withNamespace:(NSString *)endpoint withConnectionTimeout:(NSTimeInterval)connectionTimeout
107111
{
108112
if (!_isConnected && !_isConnecting) {
109113
_isConnecting = YES;
@@ -138,7 +142,7 @@ - (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDic
138142
// make a request
139143
NSURLRequest *request = [NSURLRequest requestWithURL:url
140144
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
141-
timeoutInterval:10.0];
145+
timeoutInterval:connectionTimeout];
142146

143147
_handshake = [[NSURLConnection alloc] initWithRequest:request
144148
delegate:self startImmediately:NO];

0 commit comments

Comments
 (0)