mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-22 02:53:09 +00:00
endless monitior
This commit is contained in:
@@ -512,17 +512,17 @@ local function init_all()
|
||||
end
|
||||
|
||||
local function init_template(start)
|
||||
init_all()
|
||||
init_func = {}
|
||||
start()
|
||||
init_all()
|
||||
init_all()
|
||||
init_func = {}
|
||||
start()
|
||||
init_all()
|
||||
end
|
||||
|
||||
function skynet.start(start_func)
|
||||
c.callback(dispatch_message)
|
||||
trace_handle = assert(c.stat "trace")
|
||||
skynet.timeout(0, function()
|
||||
init_template(start_func)
|
||||
init_template(start_func)
|
||||
skynet.send(".launcher","text", "")
|
||||
end)
|
||||
end
|
||||
@@ -533,7 +533,7 @@ function skynet.filter(f ,start_func)
|
||||
end)
|
||||
trace_handle = assert(c.stat "trace")
|
||||
skynet.timeout(0, function()
|
||||
init_template(start_func)
|
||||
init_template(start_func)
|
||||
skynet.send(".launcher","text", "")
|
||||
end)
|
||||
end
|
||||
@@ -550,4 +550,8 @@ function skynet.trace_callback(func)
|
||||
trace_func = func
|
||||
end
|
||||
|
||||
function skynet.endless()
|
||||
return c.command("ENDLESS")~=nil
|
||||
end
|
||||
|
||||
return skynet
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "skynet_monitor.h"
|
||||
#include "skynet_server.h"
|
||||
#include "skynet.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
@@ -34,6 +35,7 @@ void
|
||||
skynet_monitor_check(struct skynet_monitor *sm) {
|
||||
if (sm->version == sm->check_version) {
|
||||
if (sm->destination) {
|
||||
skynet_context_endless(sm->destination);
|
||||
skynet_error(NULL, "A message from [ :%08x ] to [ :%08x ] maybe in an endless loop", sm->source , sm->destination);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef CALLING_CHECK
|
||||
|
||||
@@ -40,9 +41,10 @@ struct skynet_context {
|
||||
void * cb_ud;
|
||||
skynet_cb cb;
|
||||
int session_id;
|
||||
int init;
|
||||
uint32_t forward;
|
||||
struct message_queue *queue;
|
||||
bool init;
|
||||
bool endless;
|
||||
|
||||
CHECKCALLING_DECL
|
||||
};
|
||||
@@ -79,7 +81,8 @@ skynet_context_new(const char * name, const char *param) {
|
||||
ctx->session_id = 0;
|
||||
|
||||
ctx->forward = 0;
|
||||
ctx->init = 0;
|
||||
ctx->init = false;
|
||||
ctx->endless = false;
|
||||
ctx->handle = skynet_handle_register(ctx);
|
||||
struct message_queue * queue = ctx->queue = skynet_mq_create(ctx->handle);
|
||||
// init function maybe use ctx->handle, so it must init at last
|
||||
@@ -90,7 +93,7 @@ skynet_context_new(const char * name, const char *param) {
|
||||
if (r == 0) {
|
||||
struct skynet_context * ret = skynet_context_release(ctx);
|
||||
if (ret) {
|
||||
ctx->init = 1;
|
||||
ctx->init = true;
|
||||
}
|
||||
skynet_mq_force_push(queue);
|
||||
printf("[:%x] launch %s %s\n",ret->handle, name, param ? param : "");
|
||||
@@ -147,6 +150,16 @@ skynet_context_push(uint32_t handle, struct skynet_message *message) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
skynet_context_endless(uint32_t handle) {
|
||||
struct skynet_context * ctx = skynet_handle_grab(handle);
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
ctx->endless = true;
|
||||
skynet_context_release(ctx);
|
||||
}
|
||||
|
||||
int
|
||||
skynet_isremote(struct skynet_context * ctx, uint32_t handle, int * harbor) {
|
||||
int ret = skynet_harbor_message_isremote(handle);
|
||||
@@ -333,7 +346,7 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
|
||||
}
|
||||
|
||||
if (strcmp(cmd,"LOCK") == 0) {
|
||||
if (context->init == 0) {
|
||||
if (context->init == false) {
|
||||
return NULL;
|
||||
}
|
||||
int session = strtol(param, NULL, 10);
|
||||
@@ -464,6 +477,15 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
|
||||
return _group_command(context, cmd, handle,addr);
|
||||
}
|
||||
|
||||
if (strcmp(cmd,"ENDLESS") == 0) {
|
||||
if (context->endless) {
|
||||
strcpy(context->result, "1");
|
||||
context->endless = false;
|
||||
return context->result;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,6 @@ void skynet_context_send(struct skynet_context * context, void * msg, size_t sz,
|
||||
int skynet_context_newsession(struct skynet_context *);
|
||||
int skynet_context_message_dispatch(struct skynet_monitor *); // return 1 when block
|
||||
|
||||
void skynet_context_endless(uint32_t handle); // for monitor
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user