mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 04:33:05 +00:00
debug console support simple http
This commit is contained in:
@@ -8,7 +8,43 @@ local socket_error = setmetatable({} , { __tostring = function() return "[Socket
|
||||
|
||||
sockethelper.socket_error = socket_error
|
||||
|
||||
function sockethelper.readfunc(fd)
|
||||
local function preread(fd, str)
|
||||
return function (sz)
|
||||
if str then
|
||||
if sz == #str or sz == nil then
|
||||
local ret = str
|
||||
str = nil
|
||||
return ret
|
||||
else
|
||||
if sz < #str then
|
||||
local ret = str:sub(1,sz)
|
||||
str = str:sub(sz + 1)
|
||||
return ret
|
||||
else
|
||||
sz = sz - #str
|
||||
local ret = readbytes(fd, sz)
|
||||
if ret then
|
||||
return str .. ret
|
||||
else
|
||||
error(socket_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
local ret = readbytes(fd, sz)
|
||||
if ret then
|
||||
return ret
|
||||
else
|
||||
error(socket_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function sockethelper.readfunc(fd, pre)
|
||||
if pre then
|
||||
return preread(fd, pre)
|
||||
end
|
||||
return function (sz)
|
||||
local ret = readbytes(fd, sz)
|
||||
if ret then
|
||||
|
||||
Reference in New Issue
Block a user