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

Commit cde0458

Browse files
committed
Merge commit 'c1e47f95a6ca5ccfe9e6d7812df6419ddf73b87c' into develop
+ cleanup. close #107. # Via Menno Pruijssers * commit 'c1e47f95a6ca5ccfe9e6d7812df6419ddf73b87c': Add initial connection timeout
2 parents d90e34a + c1e47f9 commit cde0458

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
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
- (void) disconnectForced;
112114

SocketIO.m

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
static NSString* kSecureHandshakePortURL = @"https://%@:%d/socket.io/1/?t=%d%@";
4343
static NSString* kSecureHandshakeURL = @"https://%@/socket.io/1/?t=%d%@";
4444

45+
float const defaultConnectionTimeout = 10.0f;
46+
4547
NSString* const SocketIOError = @"SocketIOError";
4648
NSString* const SocketIOException = @"SocketIOException";
4749

@@ -95,15 +97,27 @@ - (id) initWithDelegate:(id<SocketIODelegate>)delegate
9597

9698
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port
9799
{
98-
[self connectToHost:host onPort:port withParams:nil withNamespace:@""];
100+
[self connectToHost:host onPort:port withParams:nil withNamespace:@"" withConnectionTimeout:defaultConnectionTimeout];
99101
}
100102

101103
- (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDictionary *)params
102104
{
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];
104114
}
105115

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
107121
{
108122
if (!_isConnected && !_isConnecting) {
109123
_isConnecting = YES;
@@ -138,7 +152,7 @@ - (void) connectToHost:(NSString *)host onPort:(NSInteger)port withParams:(NSDic
138152
// make a request
139153
NSURLRequest *request = [NSURLRequest requestWithURL:url
140154
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
141-
timeoutInterval:10.0];
155+
timeoutInterval:connectionTimeout];
142156

143157
_handshake = [[NSURLConnection alloc] initWithRequest:request
144158
delegate:self startImmediately:NO];
@@ -178,7 +192,7 @@ - (void) disconnectForced
178192

179193
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
180194

181-
if(error || [response statusCode] != 200) {
195+
if (error || [response statusCode] != 200) {
182196
DEBUGLOG(@"Error during disconnect: %@", error);
183197
}
184198

@@ -268,7 +282,7 @@ - (void) sendHeartbeat
268282

269283
- (void) send:(SocketIOPacket *)packet
270284
{
271-
if(![self isConnected] && ![self isConnecting]) {
285+
if (![self isConnected] && ![self isConnecting]) {
272286
DEBUGLOG(@"Already disconnected!");
273287
return;
274288
}

0 commit comments

Comments
 (0)