mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add service manager
This commit is contained in:
17
gate/main.c
17
gate/main.c
@@ -81,9 +81,10 @@ _ctrl(struct skynet_context * ctx, struct gate * g, const void * msg, int sz) {
|
|||||||
_parm(tmp, sz, i);
|
_parm(tmp, sz, i);
|
||||||
int uid = strtol(command , NULL, 10);
|
int uid = strtol(command , NULL, 10);
|
||||||
struct connection * agent = _id_to_agent(g,uid);
|
struct connection * agent = _id_to_agent(g,uid);
|
||||||
int connection_id = agent->connection_id;
|
if (agent) {
|
||||||
|
int connection_id = agent->connection_id;
|
||||||
mread_close_client(g->pool,connection_id);
|
mread_close_client(g->pool,connection_id);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (memcmp(command,"forward",i)==0) {
|
if (memcmp(command,"forward",i)==0) {
|
||||||
@@ -168,10 +169,12 @@ static void
|
|||||||
_remove_id(struct gate *g, int uid) {
|
_remove_id(struct gate *g, int uid) {
|
||||||
struct connection ** pconn = &g->agent[uid & (g->cap - 1)];
|
struct connection ** pconn = &g->agent[uid & (g->cap - 1)];
|
||||||
struct connection * conn = *pconn;
|
struct connection * conn = *pconn;
|
||||||
assert(conn->uid == uid);
|
if (conn) {
|
||||||
conn->uid = 0;
|
assert(conn->uid == uid);
|
||||||
conn->agent = 0;
|
conn->uid = 0;
|
||||||
*pconn = NULL;
|
conn->agent = 0;
|
||||||
|
*pconn = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
|
|
||||||
local SERVICE = "GROUPMGR"
|
local SERVICE
|
||||||
|
|
||||||
local group = {}
|
local group = {}
|
||||||
|
|
||||||
@@ -27,4 +27,9 @@ function group.release(id)
|
|||||||
skynet.send(SERVICE, "lua" , "CLEAR", skynet.self(), id)
|
skynet.send(SERVICE, "lua" , "CLEAR", skynet.self(), id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
skynet.init(function()
|
||||||
|
SERVICE = skynet.call("SERVICE", "lua", "group_mgr")
|
||||||
|
skynet.call(".service","lua","group_agent")
|
||||||
|
end, "group")
|
||||||
|
|
||||||
return group
|
return group
|
||||||
@@ -3,6 +3,8 @@ local string = string
|
|||||||
local table = table
|
local table = table
|
||||||
local unpack = unpack
|
local unpack = unpack
|
||||||
|
|
||||||
|
local redis_manager
|
||||||
|
|
||||||
local redis = {}
|
local redis = {}
|
||||||
|
|
||||||
local command = {}
|
local command = {}
|
||||||
@@ -30,9 +32,13 @@ local meta = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function redis.connect(dbname)
|
function redis.connect(dbname)
|
||||||
local handle = skynet.call(".redis-manager", "lua", dbname)
|
local handle = skynet.call(redis_manager, "lua", dbname)
|
||||||
assert(handle ~= nil)
|
assert(handle ~= nil)
|
||||||
return setmetatable({ __handle = handle } , meta)
|
return setmetatable({ __handle = handle } , meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
skynet.init(function()
|
||||||
|
redis_manager = skynet.call(".service", "lua", "redis-mgr")
|
||||||
|
end, "redis")
|
||||||
|
|
||||||
return redis
|
return redis
|
||||||
|
|||||||
@@ -402,9 +402,34 @@ do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local init_func = {}
|
||||||
|
|
||||||
|
function skynet.init(f, name)
|
||||||
|
assert(type(f) == "function")
|
||||||
|
if init_func == nil then
|
||||||
|
f()
|
||||||
|
else
|
||||||
|
if name == nil then
|
||||||
|
table.insert(init_func, f)
|
||||||
|
else
|
||||||
|
assert(init_func[name] == nil)
|
||||||
|
init_func[name] = f
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function init_all()
|
||||||
|
local funcs = init_func
|
||||||
|
init_func = nil
|
||||||
|
for k,v in pairs(funcs) do
|
||||||
|
v()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function skynet.start(f)
|
function skynet.start(f)
|
||||||
c.callback(dispatch_message)
|
c.callback(dispatch_message)
|
||||||
skynet.timeout(0, function()
|
skynet.timeout(0, function()
|
||||||
|
init_all()
|
||||||
f()
|
f()
|
||||||
skynet.send(".launcher","lua", nil)
|
skynet.send(".launcher","lua", nil)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -2,15 +2,13 @@ local skynet = require "skynet"
|
|||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
print("Server start")
|
print("Server start")
|
||||||
|
local service = skynet.launch("snlua","service_mgr")
|
||||||
local connection = skynet.launch("connection","256")
|
local connection = skynet.launch("connection","256")
|
||||||
local lualog = skynet.launch("snlua","lualog")
|
local lualog = skynet.launch("snlua","lualog")
|
||||||
local console = skynet.launch("snlua","console")
|
local console = skynet.launch("snlua","console")
|
||||||
local group_mgr = skynet.launch("snlua", "group_mgr")
|
|
||||||
local group_agent = skynet.launch("snlua", "group_agent")
|
|
||||||
local remoteroot = skynet.launch("snlua","remote_root")
|
local remoteroot = skynet.launch("snlua","remote_root")
|
||||||
local watchdog = skynet.launch("snlua","watchdog","8888 4 0")
|
local watchdog = skynet.launch("snlua","watchdog","8888 4 0")
|
||||||
local db = skynet.launch("snlua","simpledb")
|
local db = skynet.launch("snlua","simpledb")
|
||||||
local redis = skynet.launch("snlua","redis-mgr")
|
|
||||||
-- skynet.launch("snlua","testgroup")
|
-- skynet.launch("snlua","testgroup")
|
||||||
|
|
||||||
skynet.exit()
|
skynet.exit()
|
||||||
|
|||||||
@@ -22,6 +22,5 @@ skynet.start(function()
|
|||||||
connection[dbname] = redis_cli
|
connection[dbname] = redis_cli
|
||||||
skynet.ret(skynet.pack(redis_cli))
|
skynet.ret(skynet.pack(redis_cli))
|
||||||
end)
|
end)
|
||||||
skynet.register ".redis-manager"
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user