Skip to content

Commit

Permalink
Eliminate delay in restarting CouchDB when app resumes
Browse files Browse the repository at this point in the history
* Instead of restarting the entire Erlang VM, just restart the couch_httpd server, which is very fast.
* On wake, check whether the listener socket is still alive, and only restart if it's not.

Change-Id: I00dcd8cf23ca5d9895c07f7f61e698926df1315a
Reviewed-on: http://review.couchbase.org/11017
Tested-by: Farshid Ghods <farshid.ghods@gmail.com>
Reviewed-by: Chris Anderson <jchris@couchbase.com>
  • Loading branch information
snej committed Nov 21, 2011
1 parent 5f9793d commit 8fbac94
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Framework/Classes/CouchbaseMobile.m
Expand Up @@ -192,11 +192,27 @@ - (BOOL)start
return YES;
}

- (BOOL)isServerRunning {
int port = [_serverURL.port intValue];
if (!port)
return NO;
struct sockaddr_in addr = {sizeof(struct sockaddr_in), AF_INET, htons(port), {0}};
int sockfd = socket(AF_INET,SOCK_STREAM, 0);
int result = connect(sockfd,(struct sockaddr*) &addr, sizeof(addr));
int connect_errno = errno;
close(sockfd);
if (_logLevel >= 2 && result != 0)
NSLog(@"Couchbase: Server not responding (errno=%i)", connect_errno);
return result == 0;
}

- (void) maybeRestart {
if (_autoRestart) [self restart];
if (_autoRestart && _serverURL && ![self isServerRunning])
[self restart];
}

- (void) restart {
_timeStarted = CFAbsoluteTimeGetCurrent();
[[NSNotificationCenter defaultCenter]
postNotificationName:kInternalRestartCouchNotification object:nil];
}
Expand Down

0 comments on commit 8fbac94

Please sign in to comment.