launch logger in C

This commit is contained in:
Cloud Wu
2014-06-19 22:12:29 +08:00
parent e4197daa54
commit 1a44bfb09a
6 changed files with 22 additions and 4 deletions

View File

@@ -2,8 +2,6 @@ local skynet = require "skynet"
local harbor = require "skynet.harbor" local harbor = require "skynet.harbor"
skynet.start(function() skynet.start(function()
assert(skynet.launch("logger", skynet.getenv "logger"))
local standalone = skynet.getenv "standalone" local standalone = skynet.getenv "standalone"
local harbor_id = tonumber(skynet.getenv "harbor") local harbor_id = tonumber(skynet.getenv "harbor")
if harbor_id == 0 then if harbor_id == 0 then

View File

@@ -7,6 +7,7 @@ struct skynet_config {
const char * daemon; const char * daemon;
const char * module_path; const char * module_path;
const char * bootstrap; const char * bootstrap;
const char * logger;
}; };
#define THREAD_WORKER 0 #define THREAD_WORKER 0

View File

@@ -115,6 +115,7 @@ main(int argc, char *argv[]) {
config.harbor = optint("harbor", 1); config.harbor = optint("harbor", 1);
config.bootstrap = optstring("bootstrap","snlua bootstrap"); config.bootstrap = optstring("bootstrap","snlua bootstrap");
config.daemon = optstring("daemon", NULL); config.daemon = optstring("daemon", NULL);
config.logger = optstring("logger", NULL);
lua_close(L); lua_close(L);

View File

@@ -234,6 +234,16 @@ _dispatch_message(struct skynet_context *ctx, struct skynet_message *msg) {
CHECKCALLING_END(ctx) CHECKCALLING_END(ctx)
} }
void
skynet_context_dispatchall(struct skynet_context * ctx) {
// for skynet_error
struct skynet_message msg;
struct message_queue *q = ctx->queue;
while (!skynet_mq_pop(q,&msg)) {
_dispatch_message(ctx, &msg);
}
}
struct message_queue * struct message_queue *
skynet_context_message_dispatch(struct skynet_monitor *sm, struct message_queue *q) { skynet_context_message_dispatch(struct skynet_monitor *sm, struct message_queue *q) {
if (q == NULL) { if (q == NULL) {

View File

@@ -18,6 +18,7 @@ void skynet_context_send(struct skynet_context * context, void * msg, size_t sz,
int skynet_context_newsession(struct skynet_context *); int skynet_context_newsession(struct skynet_context *);
struct message_queue * skynet_context_message_dispatch(struct skynet_monitor *, struct message_queue *); // return next queue struct message_queue * skynet_context_message_dispatch(struct skynet_monitor *, struct message_queue *); // return next queue
int skynet_context_total(); int skynet_context_total();
void skynet_context_dispatchall(struct skynet_context * context); // for skynet_error output before exit
void skynet_context_endless(uint32_t handle); // for monitor void skynet_context_endless(uint32_t handle); // for monitor

View File

@@ -184,7 +184,7 @@ _start(int thread) {
} }
static void static void
bootstrap(const char * cmdline) { bootstrap(struct skynet_context * logger, const char * cmdline) {
int sz = strlen(cmdline); int sz = strlen(cmdline);
char name[sz+1]; char name[sz+1];
char args[sz+1]; char args[sz+1];
@@ -192,6 +192,7 @@ bootstrap(const char * cmdline) {
struct skynet_context *ctx = skynet_context_new(name, args); struct skynet_context *ctx = skynet_context_new(name, args);
if (ctx == NULL) { if (ctx == NULL) {
skynet_error(NULL, "Bootstrap error : %s\n", cmdline); skynet_error(NULL, "Bootstrap error : %s\n", cmdline);
skynet_context_dispatchall(logger);
exit(1); exit(1);
} }
} }
@@ -210,7 +211,13 @@ skynet_start(struct skynet_config * config) {
skynet_timer_init(); skynet_timer_init();
skynet_socket_init(); skynet_socket_init();
bootstrap(config->bootstrap); struct skynet_context *ctx = skynet_context_new("logger", config->logger);
if (ctx == NULL) {
fprintf(stderr, "Can't launch logger service\n");
exit(1);
}
bootstrap(ctx, config->bootstrap);
_start(config->thread); _start(config->thread);
skynet_socket_free(); skynet_socket_free();