new socket service and socket lib instead of old connection, and rewrite redis lib

This commit is contained in:
云风
2013-06-21 13:02:51 +08:00
parent 0ffd9b8b8e
commit 277b6957cb
16 changed files with 1182 additions and 1248 deletions

View File

@@ -1,46 +1,15 @@
local skynet = require "skynet"
local socket = require "socket"
local function readline(sep)
while true do
local line = socket.readline(sep)
if line then
return line
end
coroutine.yield()
end
end
local function split_package()
while true do
local cmd = readline "\n"
if cmd ~= "" then
skynet.send(skynet.self(), "text", cmd)
end
end
end
local split_co = coroutine.create(split_package)
skynet.register_protocol {
name = "client",
id = 3,
pack = function(...) return ... end,
unpack = function(msg,sz)
assert(msg , "Stdin closed")
socket.push(msg,sz)
assert(coroutine.resume(split_co))
end,
dispatch = function () end
}
skynet.start(function()
skynet.dispatch("text", function (session, address, cmd)
local handle = skynet.newservice(cmd)
local stdin = socket.stdin()
socket.lock(stdin)
while true do
local cmdline = socket.readline(stdin, "\n")
local handle = skynet.newservice(cmdline)
if handle == nil then
print("Launch error:",cmd)
print("Launch error:",cmdline)
end
end)
socket.stdin()
end
socket.unlock(stdin)
end)