Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanjunxiong committed Jun 19, 2017
1 parent a3cb5b5 commit a9f8432
Show file tree
Hide file tree
Showing 19 changed files with 368 additions and 55 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ LUA_STATICLIB := ./skynet/3rd/lua/liblua.a
LUA_LIB ?= $(LUA_STATICLIB)
LUA_INC ?= ./skynet/3rd/lua

LUA_CLIB = cjson websocketnetpack clientwebsocket
LUA_CLIB = cjson websocketnetpack clientwebsocket lfs

all : $(LUA_CLIB_PATH)/cjson.so $(LUA_CLIB_PATH)/websocketnetpack.so $(LUA_CLIB_PATH)/clientwebsocket.so
all : $(LUA_CLIB_PATH)/cjson.so $(LUA_CLIB_PATH)/websocketnetpack.so $(LUA_CLIB_PATH)/clientwebsocket.so $(LUA_CLIB_PATH)/lfs.so

$(LUA_CLIB_PATH)/cjson.so : lua-cjson/fpconv.c lua-cjson/strbuf.c lua-cjson/lua_cjson.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -Ilua-cjson $^ -o $@
Expand All @@ -27,6 +27,9 @@ $(LUA_CLIB_PATH)/websocketnetpack.so : lualib-src/lua-websocketnetpack.c | $(LUA
$(LUA_CLIB_PATH)/clientwebsocket.so : lualib-src/lua-clientwebsocket.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) $^ -o $@ -lpthread

$(LUA_CLIB_PATH)/lfs.so : luafilesystem/src/lfs.c | $(LUA_CLIB_PATH)
$(CC) $(CFLAGS) $(SHARED) -Iluafilesystem/src $^ -o $@

clean :
rm -f $(LUA_CLIB_PATH)/*.so

Empty file added config/data/test.lua
Empty file.
2 changes: 1 addition & 1 deletion config/item.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
return {
[1] = {id=1, desc = "this is ggggttttitem one"},
[1] = {id=1, desc = "this is item one"},
[2] = {id=1, desc = "this is item two"},
}

Empty file added config/ll
Empty file.
2 changes: 1 addition & 1 deletion etc/config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ nodename = "node1"

--logger = "logd"
--logservice = "snlua"
--logfilename = "test"
--logfilename = "logtest"
--logfilemaxline = 2


Expand Down
4 changes: 2 additions & 2 deletions etc/runconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ return {

node1 = {
-- 当前节点控制台监听端口
debug_console_port = 8801,
debug_console_port = 8701,
-- agent 池配置
agentpool = {
name = "agent", -- 要启动缓存的 agent 文件名
Expand All @@ -24,7 +24,7 @@ return {
login_num = 2,

watchdog = {
port = 8899,
port = 8799,
maxclient = 1024,
nodelay = true,
}
Expand Down
1 change: 0 additions & 1 deletion log/test_2017-06-10_09:37:47

This file was deleted.

1 change: 0 additions & 1 deletion log/test_2017-06-10_09:38:09

This file was deleted.

2 changes: 0 additions & 2 deletions log/test_2017-06-10_09:39:16

This file was deleted.

282 changes: 282 additions & 0 deletions logtest

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions luafilesystem
Submodule luafilesystem added at 3c4e56
26 changes: 26 additions & 0 deletions lualib/lfstool.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
local lfs = require "lfs"

local M = {}


local sep = string.match (package.config, "[^\n]+")
function M.attrdir(path)
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path .. sep .. file
print("\t=> " .. f .. " <=")
local attr = lfs.attributes(f)
assert(type(attr) == "table")
if attr.mode == "directory" then
M.attrdir(f)
else
for name, value in pairs(attr) do
print(name, value)
end
end
end
end
end

return M

23 changes: 23 additions & 0 deletions lualib/libwsagentpool.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local skynet = require "skynet"

local M = {}

local agentpool
local function init()
agentpool = skynet.queryservice("agentpool")
end


function M.get()
return skynet.call(agentpool, "lua", "get")
end

function M.recycle(agent)
return skynet.call(agentpool, "lua", "recycle", agent)
end

skynet.init(init)

return M


31 changes: 22 additions & 9 deletions lualib/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,54 @@ local env = require "env"

local M = env.dispatch

local list = {
"test",
"item",
}

local function update()
skynet.timeout(100,
function()
print("update all")
M.update_all()
update()
end )
end

local function dir(path)
local lfs = require "lfs"
local ret = {}
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local file = string.match(file, "(%w+)%.lua")
if file then
table.insert(ret, file)
end
end
end
return ret
end

local reload = require "reload"
local function init()
local list = dir("config")
for k, v in pairs(list) do
log.debug("init " .. v .. " conf")
local conf = reload.loadmod(v)
builder.new(v, conf)
end
update()
end


function M.update_all()
for k, v in pairs(list) do
local conf = reload.loadmod(v)
builder.update(v, conf)
log.debug("update conf: " .. v)
end
end

function M.update(name)
local conf = require(name)
builder.update(v, conf)
local conf = reload.loadmod(name)
builder.update(name, conf)
log.debug("update conf: " .. name)
end

skynet.init(init)



34 changes: 0 additions & 34 deletions run/skynet.log

This file was deleted.

1 change: 0 additions & 1 deletion run/skynet.pid

This file was deleted.

2 changes: 1 addition & 1 deletion service/dbproxyd.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "service"
require "service"
require "dbproxy"

3 changes: 3 additions & 0 deletions service/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ skynet.start(function()
skynet.uniqueservice("debug_console", nodeconf.debug_console_port)
log.debug("start debug_console in port: " .. nodeconf.debug_console_port)

log.debug("start setupd...")
skynet.newservice("setupd")

log.debug("start dbproxyd...")
for i = 1, nodeconf.dbproxy_num do
local name = string.format(".dbproxyd%d", i)
Expand Down
1 change: 1 addition & 0 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function string.split(input, delimiter)
return arr
end


local t = string.split("hello.world", ".")
for k, v in pairs(t) do
print("v: " .. v)
Expand Down

0 comments on commit a9f8432

Please sign in to comment.