Permalink
Browse files

Eliminate delay in restarting CouchDB when app resumes

* 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: I938b4d3c8fa79c99c0fdcc0f4406a25dff646b45
Reviewed-on: http://review.couchbase.org/11016
Reviewed-by: Chris Anderson <jchris@couchbase.com>
Tested-by: Jens Alfke <jens@couchbase.com>
  • Loading branch information...
1 parent 9922e28 commit 107a86082373d70bdc3d97cc4d9d15b859748903 @snej snej committed Nov 18, 2011
Showing with 11 additions and 13 deletions.
  1. +11 −13 src/ios_drv.m
View
@@ -6,10 +6,10 @@
#include "util.h" //from emonk
/* Driver interface declarations */
-int iosdrv_init(void);
-ErlDrvData iosdrv_start(ErlDrvPort port, char *command);
-int iosdrv_control(ErlDrvData drv_data, unsigned int command, char *buf,
- int len, char **rbuf, int rlen);
+static int iosdrv_init(void);
+static ErlDrvData iosdrv_start(ErlDrvPort port, char *command);
+static int iosdrv_control(ErlDrvData drv_data, unsigned int command, char *buf,
+ int len, char **rbuf, int rlen);
ErlDrvEntry ios_driver_entry = {
iosdrv_init,
@@ -41,29 +41,27 @@ int iosdrv_control(ErlDrvData drv_data, unsigned int command, char *buf,
static ErlDrvPort iosdrv_port = 0;
static int couchdb_port = 0;
-void notificationCallback (CFNotificationCenterRef center,
+static void notificationCallback (CFNotificationCenterRef center,
void * observer,
CFStringRef name,
const void * object,
CFDictionaryRef userInfo) {
- NSLog(@"Got request to restart.");
if(iosdrv_process != 0)
{
ErlDrvTermData term[] = {ERL_DRV_ATOM, iosdrv_foregrounded, ERL_DRV_TUPLE, 1};
driver_send_term(iosdrv_port, iosdrv_process, term, sizeof(term) / sizeof(term[0]));
- iosdrv_process = 0;
}
}
-int iosdrv_init(void)
+static int iosdrv_init(void)
{
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), NULL,
notificationCallback, (CFStringRef) @"CouchDBRequestRestart",
NULL, CFNotificationSuspensionBehaviorCoalesce);
return 0;
}
-ErlDrvData iosdrv_start(ErlDrvPort port, char *command)
+static ErlDrvData iosdrv_start(ErlDrvPort port, char *command)
{
set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY);
iosdrv_foregrounded = driver_mk_atom("foregrounded");
@@ -72,14 +70,14 @@ ErlDrvData iosdrv_start(ErlDrvPort port, char *command)
return 0;
}
-int iosdrv_control(ErlDrvData drv_data, unsigned int command, char *buf,
- int len, char **rbuf, int rlen)
+static int iosdrv_control(ErlDrvData drv_data, unsigned int command, char *buf,
+ int len, char **rbuf, int rlen)
{
return -1;
}
-ERL_NIF_TERM set_port(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+static ERL_NIF_TERM set_port(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
int a;
if (!enif_get_int(env, argv[0], &a)) {
@@ -94,7 +92,7 @@ ERL_NIF_TERM get_port(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
return enif_make_int(env, couchdb_port);
}
-ERL_NIF_TERM post_notification(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+static ERL_NIF_TERM post_notification(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary name, key, value;

0 comments on commit 107a860

Please sign in to comment.