mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add module signal and hack lua to support it :)
This commit is contained in:
@@ -75,7 +75,7 @@ _query(const char * name) {
|
||||
static int
|
||||
_open_sym(struct skynet_module *mod) {
|
||||
size_t name_size = strlen(mod->name);
|
||||
char tmp[name_size + 9]; // create/init/release , longest name is release (7)
|
||||
char tmp[name_size + 9]; // create/init/release/signal , longest name is release (7)
|
||||
memcpy(tmp, mod->name, name_size);
|
||||
strcpy(tmp+name_size, "_create");
|
||||
mod->create = dlsym(mod->module, tmp);
|
||||
@@ -83,6 +83,8 @@ _open_sym(struct skynet_module *mod) {
|
||||
mod->init = dlsym(mod->module, tmp);
|
||||
strcpy(tmp+name_size, "_release");
|
||||
mod->release = dlsym(mod->module, tmp);
|
||||
strcpy(tmp+name_size, "_signal");
|
||||
mod->signal = dlsym(mod->module, tmp);
|
||||
|
||||
return mod->init == NULL;
|
||||
}
|
||||
@@ -150,6 +152,13 @@ skynet_module_instance_release(struct skynet_module *m, void *inst) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
skynet_module_instance_signal(struct skynet_module *m, void *inst, int signal) {
|
||||
if (m->signal) {
|
||||
m->signal(inst, signal);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
skynet_module_init(const char *path) {
|
||||
struct modules *m = skynet_malloc(sizeof(*m));
|
||||
|
||||
@@ -6,6 +6,7 @@ struct skynet_context;
|
||||
typedef void * (*skynet_dl_create)(void);
|
||||
typedef int (*skynet_dl_init)(void * inst, struct skynet_context *, const char * parm);
|
||||
typedef void (*skynet_dl_release)(void * inst);
|
||||
typedef void (*skynet_dl_signal)(void * inst, int signal);
|
||||
|
||||
struct skynet_module {
|
||||
const char * name;
|
||||
@@ -13,6 +14,7 @@ struct skynet_module {
|
||||
skynet_dl_create create;
|
||||
skynet_dl_init init;
|
||||
skynet_dl_release release;
|
||||
skynet_dl_signal signal;
|
||||
};
|
||||
|
||||
void skynet_module_insert(struct skynet_module *mod);
|
||||
@@ -20,6 +22,7 @@ struct skynet_module * skynet_module_query(const char * name);
|
||||
void * skynet_module_instance_create(struct skynet_module *);
|
||||
int skynet_module_instance_init(struct skynet_module *, void * inst, struct skynet_context *ctx, const char * parm);
|
||||
void skynet_module_instance_release(struct skynet_module *, void *inst);
|
||||
void skynet_module_instance_signal(struct skynet_module *, void *inst, int signal);
|
||||
|
||||
void skynet_module_init(const char *path);
|
||||
|
||||
|
||||
@@ -589,6 +589,26 @@ cmd_logoff(struct skynet_context * context, const char * param) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *
|
||||
cmd_signal(struct skynet_context * context, const char * param) {
|
||||
uint32_t handle = tohandle(context, param);
|
||||
if (handle == 0)
|
||||
return NULL;
|
||||
struct skynet_context * ctx = skynet_handle_grab(handle);
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
param = strchr(param, ' ');
|
||||
int sig = 0;
|
||||
if (param) {
|
||||
sig = strtol(param, NULL, 0);
|
||||
}
|
||||
// NOTICE: the signal function should be thread safe.
|
||||
skynet_module_instance_signal(ctx->mod, ctx->instance, sig);
|
||||
|
||||
skynet_context_release(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct command_func cmd_funcs[] = {
|
||||
{ "TIMEOUT", cmd_timeout },
|
||||
{ "REG", cmd_reg },
|
||||
@@ -607,6 +627,7 @@ static struct command_func cmd_funcs[] = {
|
||||
{ "MQLEN", cmd_mqlen },
|
||||
{ "LOGON", cmd_logon },
|
||||
{ "LOGOFF", cmd_logoff },
|
||||
{ "SIGNAL", cmd_signal },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user