exit monitor

This commit is contained in:
云风
2013-08-06 13:44:41 +08:00
parent 6be6a8171f
commit ff6e4dc762
5 changed files with 65 additions and 10 deletions

View File

@@ -49,21 +49,26 @@ struct skynet_context {
CHECKCALLING_DECL
};
static int g_total_context = 0;
struct skynet_node {
int total;
uint32_t monitor_exit;
};
static struct skynet_node G_NODE = { 0,0 };
int
skynet_context_total() {
return g_total_context;
return G_NODE.total;
}
static void
_context_inc() {
__sync_fetch_and_add(&g_total_context,1);
__sync_fetch_and_add(&G_NODE.total,1);
}
static void
_context_dec() {
__sync_fetch_and_sub(&g_total_context,1);
__sync_fetch_and_sub(&G_NODE.total,1);
}
static void
@@ -348,6 +353,17 @@ skynet_queryname(struct skynet_context * context, const char * name) {
return 0;
}
static void
handle_exit(struct skynet_context * context, uint32_t handle) {
if (G_NODE.monitor_exit) {
skynet_send(context, handle, G_NODE.monitor_exit, PTYPE_CLIENT, 0, NULL, 0);
}
if (handle == 0) {
handle = context->handle;
}
skynet_handle_retire(handle);
}
const char *
skynet_command(struct skynet_context * context, const char * cmd , const char * param) {
if (strcmp(cmd,"TIMEOUT") == 0) {
@@ -422,7 +438,7 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
}
if (strcmp(cmd,"EXIT") == 0) {
skynet_handle_retire(context->handle);
handle_exit(context, 0);
return NULL;
}
@@ -437,7 +453,7 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
// todo : kill global service
}
if (handle) {
skynet_handle_retire(handle);
handle_exit(context, handle);
}
return NULL;
}
@@ -512,6 +528,24 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
return NULL;
}
if (strcmp(cmd,"MONITOR") == 0) {
uint32_t handle;
if (param == NULL || param[0] == '\0') {
handle = context->handle;
} else {
if (param[0] == ':') {
handle = strtoul(param+1, NULL, 16);
} else if (param[0] == '.') {
handle = skynet_handle_findname(param+1);
} else {
skynet_error(context, "Can't monitor %s",param);
// todo : monitor global service
}
}
G_NODE.monitor_exit = handle;
return NULL;
}
return NULL;
}