mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
Compare commits
23 Commits
v1.0.0-alp
...
v1.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c43e90708 | ||
|
|
1f25b79722 | ||
|
|
6a9080157f | ||
|
|
5cc2ef3ac8 | ||
|
|
3baeb62b0b | ||
|
|
9e27f59033 | ||
|
|
82fa2f979c | ||
|
|
07d7324332 | ||
|
|
d92adda2c9 | ||
|
|
0587400e2d | ||
|
|
35c8c63793 | ||
|
|
c7f5145e9e | ||
|
|
9452169f0a | ||
|
|
a15f43e0f8 | ||
|
|
0eb4754b31 | ||
|
|
f987ff8199 | ||
|
|
64a5d1ca24 | ||
|
|
fa17081012 | ||
|
|
856cb0737d | ||
|
|
f61e3f46e8 | ||
|
|
6b6b943b73 | ||
|
|
75d9b07158 | ||
|
|
8682f7f82f |
13
HISTORY.md
13
HISTORY.md
@@ -1,3 +1,16 @@
|
|||||||
|
v1.0.0-alpha6 (2015-5-18)
|
||||||
|
-----------
|
||||||
|
* bugfix: httpc.get
|
||||||
|
* bugfix: seri lib stack overflow
|
||||||
|
* bugfix: udp send
|
||||||
|
* bugfix: udp address
|
||||||
|
* bugfix: sproto dump
|
||||||
|
* add: sproto default
|
||||||
|
* improve: skynet.wakeup (can wakeup skynet.call by raise an error)
|
||||||
|
* improve: skynet.exit (raise error when uncall response)
|
||||||
|
* remove: task overload warning
|
||||||
|
* move: some skynet api move into skynet.manager
|
||||||
|
|
||||||
v1.0.0-alpha5 (2015-4-27)
|
v1.0.0-alpha5 (2015-4-27)
|
||||||
-----------
|
-----------
|
||||||
* merge lua 5.3 offical bugfix
|
* merge lua 5.3 offical bugfix
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
|
require "skynet.manager" -- import skynet.abort
|
||||||
|
|
||||||
skynet.abort()
|
skynet.abort()
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
local cluster = require "cluster"
|
local cluster = require "cluster"
|
||||||
|
require "skynet.manager" -- import skynet.name
|
||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
local sdb = skynet.newservice("simpledb")
|
local sdb = skynet.newservice("simpledb")
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
|
require "skynet.manager" -- import skynet.register
|
||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
skynet.dispatch("lua", function(session, address, ...)
|
skynet.dispatch("lua", function(session, address, ...)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
local harbor = require "skynet.harbor"
|
local harbor = require "skynet.harbor"
|
||||||
|
require "skynet.manager" -- import skynet.monitor
|
||||||
|
|
||||||
local function monitor_master()
|
local function monitor_master()
|
||||||
harbor.linkmaster()
|
harbor.linkmaster()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
|
require "skynet.manager" -- import skynet.register
|
||||||
local db = {}
|
local db = {}
|
||||||
|
|
||||||
local command = {}
|
local command = {}
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ wb_table_hash(lua_State *L, struct write_block * wb, int index, int depth, int a
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
wb_table(lua_State *L, struct write_block *wb, int index, int depth) {
|
wb_table(lua_State *L, struct write_block *wb, int index, int depth) {
|
||||||
|
luaL_checkstack(L, LUA_MINSTACK, NULL);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
index = lua_gettop(L) + index + 1;
|
index = lua_gettop(L) + index + 1;
|
||||||
}
|
}
|
||||||
@@ -416,6 +417,7 @@ unpack_table(lua_State *L, struct read_block *rb, int array_size) {
|
|||||||
}
|
}
|
||||||
array_size = get_integer(L,rb,cookie);
|
array_size = get_integer(L,rb,cookie);
|
||||||
}
|
}
|
||||||
|
luaL_checkstack(L,LUA_MINSTACK,NULL);
|
||||||
lua_createtable(L,array_size,0);
|
lua_createtable(L,array_size,0);
|
||||||
int i;
|
int i;
|
||||||
for (i=1;i<=array_size;i++) {
|
for (i=1;i<=array_size;i++) {
|
||||||
@@ -549,8 +551,8 @@ _luaseri_unpack(lua_State *L) {
|
|||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i=0;;i++) {
|
for (i=0;;i++) {
|
||||||
if (i%16==15) {
|
if (i%8==7) {
|
||||||
lua_checkstack(L,i);
|
luaL_checkstack(L,LUA_MINSTACK,NULL);
|
||||||
}
|
}
|
||||||
uint8_t type = 0;
|
uint8_t type = 0;
|
||||||
uint8_t *t = rb_read(&rb, sizeof(type));
|
uint8_t *t = rb_read(&rb, sizeof(type));
|
||||||
|
|||||||
@@ -534,12 +534,6 @@ lnodelay(lua_State *L) {
|
|||||||
skynet_socket_nodelay(ctx,id);
|
skynet_socket_nodelay(ctx,id);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
int skynet_socket_udp(struct skynet_context *ctx, const char * addr, int port);
|
|
||||||
int skynet_socket_udp_connect(struct skynet_context *ctx, int id, const char * addr, int port);
|
|
||||||
int skynet_socket_udp_send(struct skynet_context *ctx, int id, const char * address, const void *buffer, int sz);
|
|
||||||
const char * skynet_socket_udp_address(struct skynet_context *ctx, struct skynet_socket_message *, int *addrsz);
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ludp(lua_State *L) {
|
ludp(lua_State *L) {
|
||||||
@@ -599,7 +593,9 @@ static int
|
|||||||
ludp_address(lua_State *L) {
|
ludp_address(lua_State *L) {
|
||||||
size_t sz = 0;
|
size_t sz = 0;
|
||||||
const uint8_t * addr = (const uint8_t *)luaL_checklstring(L, 1, &sz);
|
const uint8_t * addr = (const uint8_t *)luaL_checklstring(L, 1, &sz);
|
||||||
int port = addr[1] * 256 + addr[2];
|
uint16_t port = 0;
|
||||||
|
memcpy(&port, addr+1, sizeof(uint16_t));
|
||||||
|
port = ntohs(port);
|
||||||
const void * src = addr+3;
|
const void * src = addr+3;
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
int family;
|
int family;
|
||||||
|
|||||||
@@ -573,6 +573,55 @@ lloadproto(lua_State *L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
encode_default(const struct sproto_arg *args) {
|
||||||
|
lua_State *L = args->ud;
|
||||||
|
lua_pushstring(L, args->tagname);
|
||||||
|
if (args->index > 0) {
|
||||||
|
lua_newtable(L);
|
||||||
|
} else {
|
||||||
|
switch(args->type) {
|
||||||
|
case SPROTO_TINTEGER:
|
||||||
|
lua_pushinteger(L, 0);
|
||||||
|
break;
|
||||||
|
case SPROTO_TBOOLEAN:
|
||||||
|
lua_pushboolean(L, 0);
|
||||||
|
break;
|
||||||
|
case SPROTO_TSTRING:
|
||||||
|
lua_pushliteral(L, "");
|
||||||
|
break;
|
||||||
|
case SPROTO_TSTRUCT:
|
||||||
|
lua_createtable(L, 0, 1);
|
||||||
|
lua_pushstring(L, sproto_name(args->subtype));
|
||||||
|
lua_setfield(L, -2, "__type");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lua_rawset(L, -3);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
lightuserdata sproto_type
|
||||||
|
return default table
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
ldefault(lua_State *L) {
|
||||||
|
int ret;
|
||||||
|
// 32 is enough for dummy buffer, because ldefault encode nothing but the header.
|
||||||
|
char dummy[32];
|
||||||
|
struct sproto_type * st = lua_touserdata(L, 1);
|
||||||
|
if (st == NULL) {
|
||||||
|
return luaL_argerror(L, 1, "Need a sproto_type object");
|
||||||
|
}
|
||||||
|
lua_newtable(L);
|
||||||
|
ret = sproto_encode(st, dummy, sizeof(dummy), encode_default, L);
|
||||||
|
if (ret<0) {
|
||||||
|
return luaL_error(L, "dummy buffer (%d) is too small", (int)sizeof(dummy));
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
luaopen_sproto_core(lua_State *L) {
|
luaopen_sproto_core(lua_State *L) {
|
||||||
#ifdef luaL_checkversion
|
#ifdef luaL_checkversion
|
||||||
@@ -587,6 +636,7 @@ luaopen_sproto_core(lua_State *L) {
|
|||||||
{ "protocol", lprotocol },
|
{ "protocol", lprotocol },
|
||||||
{ "loadproto", lloadproto },
|
{ "loadproto", lloadproto },
|
||||||
{ "saveproto", lsaveproto },
|
{ "saveproto", lsaveproto },
|
||||||
|
{ "default", ldefault },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
luaL_newlib(L,l);
|
luaL_newlib(L,l);
|
||||||
|
|||||||
@@ -500,7 +500,11 @@ sproto_dump(struct sproto *s) {
|
|||||||
printf("=== %d protocol ===\n", s->protocol_n);
|
printf("=== %d protocol ===\n", s->protocol_n);
|
||||||
for (i=0;i<s->protocol_n;i++) {
|
for (i=0;i<s->protocol_n;i++) {
|
||||||
struct protocol *p = &s->proto[i];
|
struct protocol *p = &s->proto[i];
|
||||||
|
if (p->p[SPROTO_REQUEST]) {
|
||||||
printf("\t%s (%d) request:%s", p->name, p->tag, p->p[SPROTO_REQUEST]->name);
|
printf("\t%s (%d) request:%s", p->name, p->tag, p->p[SPROTO_REQUEST]->name);
|
||||||
|
} else {
|
||||||
|
printf("\t%s (%d) request:(null)", p->name, p->tag);
|
||||||
|
}
|
||||||
if (p->p[SPROTO_RESPONSE]) {
|
if (p->p[SPROTO_RESPONSE]) {
|
||||||
printf(" response:%s", p->p[SPROTO_RESPONSE]->name);
|
printf(" response:%s", p->p[SPROTO_RESPONSE]->name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,23 +11,21 @@ local function request(fd, method, host, url, recvheader, header, content)
|
|||||||
local write = socket.writefunc(fd)
|
local write = socket.writefunc(fd)
|
||||||
local header_content = ""
|
local header_content = ""
|
||||||
if header then
|
if header then
|
||||||
|
if not header.host then
|
||||||
|
header.host = host
|
||||||
|
end
|
||||||
for k,v in pairs(header) do
|
for k,v in pairs(header) do
|
||||||
header_content = string.format("%s%s:%s\r\n", header_content, k, v)
|
header_content = string.format("%s%s:%s\r\n", header_content, k, v)
|
||||||
end
|
end
|
||||||
if header.host then
|
|
||||||
host = ""
|
|
||||||
else
|
else
|
||||||
host = string.format("host:%s\r\n", host)
|
header_content = string.format("host:%s\r\n",host)
|
||||||
end
|
|
||||||
else
|
|
||||||
host = string.format("host:%s\r\n",host)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if content then
|
if content then
|
||||||
local data = string.format("%s %s HTTP/1.1\r\n%scontent-length:%d\r\n%s\r\n%s", method, url, host, #content, header_content, content)
|
local data = string.format("%s %s HTTP/1.1\r\n%scontent-length:%d\r\n\r\n%s", method, url, header_content, #content, content)
|
||||||
write(data)
|
write(data)
|
||||||
else
|
else
|
||||||
local request_header = string.format("%s %s HTTP/1.1\r\nhost:%s\r\ncontent-length:0\r\n%s\r\n", method, url, host, header_content)
|
local request_header = string.format("%s %s HTTP/1.1\r\n%scontent-length:0\r\n\r\n", method, url, header_content)
|
||||||
write(request_header)
|
write(request_header)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ local session_id_coroutine = {}
|
|||||||
local session_coroutine_id = {}
|
local session_coroutine_id = {}
|
||||||
local session_coroutine_address = {}
|
local session_coroutine_address = {}
|
||||||
local session_response = {}
|
local session_response = {}
|
||||||
|
local unresponse = {}
|
||||||
|
|
||||||
local wakeup_session = {}
|
local wakeup_session = {}
|
||||||
local sleep_session = {}
|
local sleep_session = {}
|
||||||
@@ -96,7 +97,6 @@ end
|
|||||||
|
|
||||||
local coroutine_pool = {}
|
local coroutine_pool = {}
|
||||||
local coroutine_yield = coroutine.yield
|
local coroutine_yield = coroutine.yield
|
||||||
local coroutine_count = 0
|
|
||||||
|
|
||||||
local function co_create(f)
|
local function co_create(f)
|
||||||
local co = table.remove(coroutine_pool)
|
local co = table.remove(coroutine_pool)
|
||||||
@@ -110,11 +110,6 @@ local function co_create(f)
|
|||||||
f(coroutine_yield())
|
f(coroutine_yield())
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
coroutine_count = coroutine_count + 1
|
|
||||||
if coroutine_count > 1024 then
|
|
||||||
skynet.error("May overload, create 1024 task")
|
|
||||||
coroutine_count = 0
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
coroutine.resume(co, f)
|
coroutine.resume(co, f)
|
||||||
end
|
end
|
||||||
@@ -128,7 +123,7 @@ local function dispatch_wakeup()
|
|||||||
local session = sleep_session[co]
|
local session = sleep_session[co]
|
||||||
if session then
|
if session then
|
||||||
session_id_coroutine[session] = "BREAK"
|
session_id_coroutine[session] = "BREAK"
|
||||||
return suspend(co, coroutine.resume(co, true, "BREAK"))
|
return suspend(co, coroutine.resume(co, false, "BREAK"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -175,6 +170,10 @@ function suspend(co, result, command, param, size)
|
|||||||
local ret
|
local ret
|
||||||
if not dead_service[co_address] then
|
if not dead_service[co_address] then
|
||||||
ret = c.send(co_address, skynet.PTYPE_RESPONSE, co_session, param, size) ~= nil
|
ret = c.send(co_address, skynet.PTYPE_RESPONSE, co_session, param, size) ~= nil
|
||||||
|
if not ret then
|
||||||
|
-- If the package is too large, returns nil. so we should report error back
|
||||||
|
c.send(co_address, skynet.PTYPE_ERROR, co_session, "")
|
||||||
|
end
|
||||||
elseif size == nil then
|
elseif size == nil then
|
||||||
c.trash(param, size)
|
c.trash(param, size)
|
||||||
ret = false
|
ret = false
|
||||||
@@ -209,6 +208,10 @@ function suspend(co, result, command, param, size)
|
|||||||
if not dead_service[co_address] then
|
if not dead_service[co_address] then
|
||||||
if ok then
|
if ok then
|
||||||
ret = c.send(co_address, skynet.PTYPE_RESPONSE, co_session, f(...)) ~= nil
|
ret = c.send(co_address, skynet.PTYPE_RESPONSE, co_session, f(...)) ~= nil
|
||||||
|
if not ret then
|
||||||
|
-- If the package is too large, returns false. so we should report error back
|
||||||
|
c.send(co_address, skynet.PTYPE_ERROR, co_session, "")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
ret = c.send(co_address, skynet.PTYPE_ERROR, co_session, "") ~= nil
|
ret = c.send(co_address, skynet.PTYPE_ERROR, co_session, "") ~= nil
|
||||||
end
|
end
|
||||||
@@ -216,11 +219,13 @@ function suspend(co, result, command, param, size)
|
|||||||
ret = false
|
ret = false
|
||||||
end
|
end
|
||||||
release_watching(co_address)
|
release_watching(co_address)
|
||||||
|
unresponse[response] = nil
|
||||||
f = nil
|
f = nil
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
watching_service[co_address] = watching_service[co_address] + 1
|
watching_service[co_address] = watching_service[co_address] + 1
|
||||||
session_response[co] = response
|
session_response[co] = response
|
||||||
|
unresponse[response] = true
|
||||||
return suspend(co, coroutine.resume(co, response))
|
return suspend(co, coroutine.resume(co, response))
|
||||||
elseif command == "EXIT" then
|
elseif command == "EXIT" then
|
||||||
-- coroutine exit
|
-- coroutine exit
|
||||||
@@ -257,9 +262,13 @@ function skynet.sleep(ti)
|
|||||||
session = tonumber(session)
|
session = tonumber(session)
|
||||||
local succ, ret = coroutine_yield("SLEEP", session)
|
local succ, ret = coroutine_yield("SLEEP", session)
|
||||||
sleep_session[coroutine.running()] = nil
|
sleep_session[coroutine.running()] = nil
|
||||||
assert(succ, ret)
|
if succ then
|
||||||
|
return
|
||||||
|
end
|
||||||
if ret == "BREAK" then
|
if ret == "BREAK" then
|
||||||
return "BREAK"
|
return "BREAK"
|
||||||
|
else
|
||||||
|
error(ret)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -269,41 +278,12 @@ end
|
|||||||
|
|
||||||
function skynet.wait()
|
function skynet.wait()
|
||||||
local session = c.genid()
|
local session = c.genid()
|
||||||
coroutine_yield("SLEEP", session)
|
local ret, msg = coroutine_yield("SLEEP", session)
|
||||||
local co = coroutine.running()
|
local co = coroutine.running()
|
||||||
sleep_session[co] = nil
|
sleep_session[co] = nil
|
||||||
session_id_coroutine[session] = nil
|
session_id_coroutine[session] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function globalname(name, handle)
|
|
||||||
local c = string.sub(name,1,1)
|
|
||||||
assert(c ~= ':')
|
|
||||||
if c == '.' then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
assert(#name <= 16) -- GLOBALNAME_LENGTH is 16, defined in skynet_harbor.h
|
|
||||||
assert(tonumber(name) == nil) -- global name can't be number
|
|
||||||
|
|
||||||
local harbor = require "skynet.harbor"
|
|
||||||
|
|
||||||
harbor.globalname(name, handle)
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function skynet.register(name)
|
|
||||||
if not globalname(name) then
|
|
||||||
c.command("REG", name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function skynet.name(name, handle)
|
|
||||||
if not globalname(name, handle) then
|
|
||||||
c.command("NAME", name .. " " .. skynet.address(handle))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local self_handle
|
local self_handle
|
||||||
function skynet.self()
|
function skynet.self()
|
||||||
if self_handle then
|
if self_handle then
|
||||||
@@ -320,13 +300,6 @@ function skynet.localname(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.launch(...)
|
|
||||||
local addr = c.command("LAUNCH", table.concat({...}," "))
|
|
||||||
if addr then
|
|
||||||
return string_to_handle(addr)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function skynet.now()
|
function skynet.now()
|
||||||
return tonumber(c.command("NOW"))
|
return tonumber(c.command("NOW"))
|
||||||
end
|
end
|
||||||
@@ -349,6 +322,9 @@ function skynet.exit()
|
|||||||
c.redirect(address, 0, skynet.PTYPE_ERROR, session, "")
|
c.redirect(address, 0, skynet.PTYPE_ERROR, session, "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
for resp in pairs(unresponse) do
|
||||||
|
resp(false)
|
||||||
|
end
|
||||||
-- report the sources I call but haven't return
|
-- report the sources I call but haven't return
|
||||||
local tmp = {}
|
local tmp = {}
|
||||||
for session, address in pairs(watching_session) do
|
for session, address in pairs(watching_session) do
|
||||||
@@ -362,14 +338,6 @@ function skynet.exit()
|
|||||||
coroutine_yield "QUIT"
|
coroutine_yield "QUIT"
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.kill(name)
|
|
||||||
if type(name) == "number" then
|
|
||||||
skynet.send(".launcher","lua","REMOVE",name, true)
|
|
||||||
name = skynet.address(name)
|
|
||||||
end
|
|
||||||
c.command("KILL",name)
|
|
||||||
end
|
|
||||||
|
|
||||||
function skynet.getenv(key)
|
function skynet.getenv(key)
|
||||||
local ret = c.command("GETENV",key)
|
local ret = c.command("GETENV",key)
|
||||||
if ret == "" then
|
if ret == "" then
|
||||||
@@ -405,7 +373,7 @@ local function yield_call(service, session)
|
|||||||
local succ, msg, sz = coroutine_yield("CALL", session)
|
local succ, msg, sz = coroutine_yield("CALL", session)
|
||||||
watching_session[session] = nil
|
watching_session[session] = nil
|
||||||
if not succ then
|
if not succ then
|
||||||
error(debug.traceback())
|
error "call failed"
|
||||||
end
|
end
|
||||||
return msg,sz
|
return msg,sz
|
||||||
end
|
end
|
||||||
@@ -516,7 +484,7 @@ local function raw_dispatch_message(prototype, msg, sz, session, source, ...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function dispatch_message(...)
|
function skynet.dispatch_message(...)
|
||||||
local succ, err = pcall(raw_dispatch_message,...)
|
local succ, err = pcall(raw_dispatch_message,...)
|
||||||
while true do
|
while true do
|
||||||
local key,co = next(fork_queue)
|
local key,co = next(fork_queue)
|
||||||
@@ -638,7 +606,7 @@ function skynet.pcall(start)
|
|||||||
return xpcall(init_template, debug.traceback, start)
|
return xpcall(init_template, debug.traceback, start)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function init_service(start)
|
function skynet.init_service(start)
|
||||||
local ok, err = skynet.pcall(start)
|
local ok, err = skynet.pcall(start)
|
||||||
if not ok then
|
if not ok then
|
||||||
skynet.error("init service failed: " .. tostring(err))
|
skynet.error("init service failed: " .. tostring(err))
|
||||||
@@ -650,33 +618,9 @@ local function init_service(start)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function skynet.start(start_func)
|
function skynet.start(start_func)
|
||||||
c.callback(dispatch_message)
|
c.callback(skynet.dispatch_message)
|
||||||
skynet.timeout(0, function()
|
skynet.timeout(0, function()
|
||||||
init_service(start_func)
|
skynet.init_service(start_func)
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function skynet.filter(f ,start_func)
|
|
||||||
c.callback(function(...)
|
|
||||||
dispatch_message(f(...))
|
|
||||||
end)
|
|
||||||
skynet.timeout(0, function()
|
|
||||||
init_service(start_func)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function skynet.forward_type(map, start_func)
|
|
||||||
c.callback(function(ptype, msg, sz, ...)
|
|
||||||
local prototype = map[ptype]
|
|
||||||
if prototype then
|
|
||||||
dispatch_message(prototype, msg, sz, ...)
|
|
||||||
else
|
|
||||||
dispatch_message(ptype, msg, sz, ...)
|
|
||||||
c.trash(msg, sz)
|
|
||||||
end
|
|
||||||
end, true)
|
|
||||||
skynet.timeout(0, function()
|
|
||||||
init_service(start_func)
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -684,22 +628,6 @@ function skynet.endless()
|
|||||||
return c.command("ENDLESS")~=nil
|
return c.command("ENDLESS")~=nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function skynet.abort()
|
|
||||||
c.command("ABORT")
|
|
||||||
end
|
|
||||||
|
|
||||||
function skynet.monitor(service, query)
|
|
||||||
local monitor
|
|
||||||
if query then
|
|
||||||
monitor = skynet.queryservice(true, service)
|
|
||||||
else
|
|
||||||
monitor = skynet.uniqueservice(true, service)
|
|
||||||
end
|
|
||||||
assert(monitor, "Monitor launch failed")
|
|
||||||
c.command("MONITOR", string.format(":%08x", monitor))
|
|
||||||
return monitor
|
|
||||||
end
|
|
||||||
|
|
||||||
function skynet.mqlen()
|
function skynet.mqlen()
|
||||||
return tonumber(c.command "MQLEN")
|
return tonumber(c.command "MQLEN")
|
||||||
end
|
end
|
||||||
@@ -726,7 +654,7 @@ end
|
|||||||
-- Inject internal debug framework
|
-- Inject internal debug framework
|
||||||
local debug = require "skynet.debug"
|
local debug = require "skynet.debug"
|
||||||
debug(skynet, {
|
debug(skynet, {
|
||||||
dispatch = dispatch_message,
|
dispatch = skynet.dispatch_message,
|
||||||
clear = clear_pool,
|
clear = clear_pool,
|
||||||
suspend = suspend,
|
suspend = suspend,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
local function getupvaluetable(u, func, unique)
|
local function getupvaluetable(u, func, unique)
|
||||||
i = 1
|
local i = 1
|
||||||
while true do
|
while true do
|
||||||
local name, value = debug.getupvalue(func, i)
|
local name, value = debug.getupvalue(func, i)
|
||||||
if name == nil then
|
if name == nil then
|
||||||
|
|||||||
90
lualib/skynet/manager.lua
Normal file
90
lualib/skynet/manager.lua
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
local skynet = require "skynet"
|
||||||
|
local c = require "skynet.core"
|
||||||
|
|
||||||
|
function skynet.launch(...)
|
||||||
|
local addr = c.command("LAUNCH", table.concat({...}," "))
|
||||||
|
if addr then
|
||||||
|
return tonumber("0x" .. string.sub(addr , 2))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function skynet.kill(name)
|
||||||
|
if type(name) == "number" then
|
||||||
|
skynet.send(".launcher","lua","REMOVE",name, true)
|
||||||
|
name = skynet.address(name)
|
||||||
|
end
|
||||||
|
c.command("KILL",name)
|
||||||
|
end
|
||||||
|
|
||||||
|
function skynet.abort()
|
||||||
|
c.command("ABORT")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function globalname(name, handle)
|
||||||
|
local c = string.sub(name,1,1)
|
||||||
|
assert(c ~= ':')
|
||||||
|
if c == '.' then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
assert(#name <= 16) -- GLOBALNAME_LENGTH is 16, defined in skynet_harbor.h
|
||||||
|
assert(tonumber(name) == nil) -- global name can't be number
|
||||||
|
|
||||||
|
local harbor = require "skynet.harbor"
|
||||||
|
|
||||||
|
harbor.globalname(name, handle)
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function skynet.register(name)
|
||||||
|
if not globalname(name) then
|
||||||
|
c.command("REG", name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function skynet.name(name, handle)
|
||||||
|
if not globalname(name, handle) then
|
||||||
|
c.command("NAME", name .. " " .. skynet.address(handle))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local dispatch_message = skynet.dispatch_message
|
||||||
|
|
||||||
|
function skynet.forward_type(map, start_func)
|
||||||
|
c.callback(function(ptype, msg, sz, ...)
|
||||||
|
local prototype = map[ptype]
|
||||||
|
if prototype then
|
||||||
|
dispatch_message(prototype, msg, sz, ...)
|
||||||
|
else
|
||||||
|
dispatch_message(ptype, msg, sz, ...)
|
||||||
|
c.trash(msg, sz)
|
||||||
|
end
|
||||||
|
end, true)
|
||||||
|
skynet.timeout(0, function()
|
||||||
|
skynet.init_service(start_func)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function skynet.filter(f ,start_func)
|
||||||
|
c.callback(function(...)
|
||||||
|
dispatch_message(f(...))
|
||||||
|
end)
|
||||||
|
skynet.timeout(0, function()
|
||||||
|
skynet.init_service(start_func)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function skynet.monitor(service, query)
|
||||||
|
local monitor
|
||||||
|
if query then
|
||||||
|
monitor = skynet.queryservice(true, service)
|
||||||
|
else
|
||||||
|
monitor = skynet.uniqueservice(true, service)
|
||||||
|
end
|
||||||
|
assert(monitor, "Monitor launch failed")
|
||||||
|
c.command("MONITOR", string.format(":%08x", monitor))
|
||||||
|
return monitor
|
||||||
|
end
|
||||||
|
|
||||||
|
return skynet
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
|
require "skynet.manager"
|
||||||
local socket = require "socket"
|
local socket = require "socket"
|
||||||
local crypt = require "crypt"
|
local crypt = require "crypt"
|
||||||
local table = table
|
local table = table
|
||||||
|
|||||||
@@ -101,27 +101,64 @@ end
|
|||||||
|
|
||||||
function sproto:request_encode(protoname, tbl)
|
function sproto:request_encode(protoname, tbl)
|
||||||
local p = queryproto(self, protoname)
|
local p = queryproto(self, protoname)
|
||||||
return core.encode(p.request,tbl) , p.tag
|
local request = p.request
|
||||||
|
if request then
|
||||||
|
return core.encode(request,tbl) , p.tag
|
||||||
|
else
|
||||||
|
return "" , p.tag
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function sproto:response_encode(protoname, tbl)
|
function sproto:response_encode(protoname, tbl)
|
||||||
local p = queryproto(self, protoname)
|
local p = queryproto(self, protoname)
|
||||||
return core.encode(p.response,tbl)
|
local response = p.response
|
||||||
|
if response then
|
||||||
|
return core.encode(response,tbl)
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function sproto:request_decode(protoname, ...)
|
function sproto:request_decode(protoname, ...)
|
||||||
local p = queryproto(self, protoname)
|
local p = queryproto(self, protoname)
|
||||||
return core.decode(p.request,...) , p.name
|
local request = p.request
|
||||||
|
if request then
|
||||||
|
return core.decode(request,...) , p.name
|
||||||
|
else
|
||||||
|
return nil, p.name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function sproto:response_decode(protoname, ...)
|
function sproto:response_decode(protoname, ...)
|
||||||
local p = queryproto(self, protoname)
|
local p = queryproto(self, protoname)
|
||||||
return core.decode(p.response,...)
|
local response = p.response
|
||||||
|
if response then
|
||||||
|
return core.decode(response,...)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sproto.pack = core.pack
|
sproto.pack = core.pack
|
||||||
sproto.unpack = core.unpack
|
sproto.unpack = core.unpack
|
||||||
|
|
||||||
|
function sproto:default(typename, type)
|
||||||
|
if type == nil then
|
||||||
|
return core.default(querytype(self, typename))
|
||||||
|
else
|
||||||
|
local p = queryproto(self, typename)
|
||||||
|
if type == "REQUEST" then
|
||||||
|
if p.request then
|
||||||
|
return core.default(p.request)
|
||||||
|
end
|
||||||
|
elseif type == "RESPONSE" then
|
||||||
|
if p.response then
|
||||||
|
return core.default(p.response)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
error "Invalid type"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local header_tmp = {}
|
local header_tmp = {}
|
||||||
|
|
||||||
local function gen_response(self, response, session)
|
local function gen_response(self, response, session)
|
||||||
|
|||||||
@@ -340,9 +340,6 @@ local function packtype(name, t, alltypes)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function packproto(name, p, alltypes)
|
local function packproto(name, p, alltypes)
|
||||||
-- if p.request == nil then
|
|
||||||
-- error(string.format("Protocol %s need request", name))
|
|
||||||
-- end
|
|
||||||
if p.request then
|
if p.request then
|
||||||
local request = alltypes[p.request]
|
local request = alltypes[p.request]
|
||||||
if request == nil then
|
if request == nil then
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
local harbor = require "skynet.harbor"
|
local harbor = require "skynet.harbor"
|
||||||
|
require "skynet.manager" -- import skynet.launch, ...
|
||||||
|
|
||||||
skynet.start(function()
|
skynet.start(function()
|
||||||
local standalone = skynet.getenv "standalone"
|
local standalone = skynet.getenv "standalone"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
|
require "skynet.manager" -- import skynet.launch, ...
|
||||||
|
|
||||||
local globalname = {}
|
local globalname = {}
|
||||||
local queryname = {}
|
local queryname = {}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
local cluster = require "cluster"
|
local cluster = require "cluster"
|
||||||
|
require "skynet.manager" -- inject skynet.forward_type
|
||||||
|
|
||||||
local node, address = ...
|
local node, address = ...
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
local socket = require "socket"
|
local socket = require "socket"
|
||||||
|
require "skynet.manager" -- import skynet.launch, ...
|
||||||
local table = table
|
local table = table
|
||||||
|
|
||||||
local slaves = {}
|
local slaves = {}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
local core = require "skynet.core"
|
local core = require "skynet.core"
|
||||||
|
require "skynet.manager" -- import manager apis
|
||||||
local string = string
|
local string = string
|
||||||
|
|
||||||
local services = {}
|
local services = {}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
|
require "skynet.manager" -- import skynet.register
|
||||||
local snax = require "snax"
|
local snax = require "snax"
|
||||||
|
|
||||||
local cmd = {}
|
local cmd = {}
|
||||||
|
|||||||
@@ -508,7 +508,7 @@ udp_socket_address(struct socket *s, const uint8_t udp_address[UDP_ADDRESS_SIZE]
|
|||||||
memset(&sa->v6, 0, sizeof(sa->v6));
|
memset(&sa->v6, 0, sizeof(sa->v6));
|
||||||
sa->s.sa_family = AF_INET6;
|
sa->s.sa_family = AF_INET6;
|
||||||
sa->v6.sin6_port = port;
|
sa->v6.sin6_port = port;
|
||||||
memcpy(&sa->v6.sin6_addr, udp_address + 1 + sizeof(uint16_t), sizeof(sa->v6.sin6_addr)); // ipv4 address is 128 bits
|
memcpy(&sa->v6.sin6_addr, udp_address + 1 + sizeof(uint16_t), sizeof(sa->v6.sin6_addr)); // ipv6 address is 128 bits
|
||||||
return sizeof(sa->v6);
|
return sizeof(sa->v6);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -720,6 +720,7 @@ send_socket(struct socket_server *ss, struct request_send * request, struct sock
|
|||||||
append_sendbuffer_udp(ss,s,priority,request,udp_address);
|
append_sendbuffer_udp(ss,s,priority,request,udp_address);
|
||||||
} else {
|
} else {
|
||||||
so.free_func(request->buffer);
|
so.free_func(request->buffer);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sp_write(ss->event_fd, s->fd, s, true);
|
sp_write(ss->event_fd, s->fd, s, true);
|
||||||
@@ -887,6 +888,7 @@ add_udp_socket(struct socket_server *ss, struct request_udp *udp) {
|
|||||||
if (ns == NULL) {
|
if (ns == NULL) {
|
||||||
close(udp->fd);
|
close(udp->fd);
|
||||||
ss->slot[HASH_ID(id)].type = SOCKET_TYPE_INVALID;
|
ss->slot[HASH_ID(id)].type = SOCKET_TYPE_INVALID;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
ns->type = SOCKET_TYPE_CONNECTED;
|
ns->type = SOCKET_TYPE_CONNECTED;
|
||||||
memset(ns->p.udp_address, 0, sizeof(ns->p.udp_address));
|
memset(ns->p.udp_address, 0, sizeof(ns->p.udp_address));
|
||||||
|
|||||||
Reference in New Issue
Block a user