mirror of
https://github.com/lxsang/silk.git
synced 2024-12-26 04:48:21 +01:00
add support for luad websocket
This commit is contained in:
parent
356b96dfcc
commit
d1ba380488
@ -167,35 +167,35 @@ function std.is_file(f)
|
|||||||
return ulib.is_dir(f) == false
|
return ulib.is_dir(f) == false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO provide web socket support
|
-- TODO use coroutine to read socket message
|
||||||
-- use coroutine to read socket message
|
|
||||||
std.ws = {}
|
std.ws = {}
|
||||||
function std.ws.header()
|
function std.ws.header()
|
||||||
local h = std.ws_header(HTTP_REQUEST.id)
|
if not fcgio:is_ws() then return nil end
|
||||||
if (h) then
|
return fcgio:ws_header()
|
||||||
return h -- std.readOnly(h)
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function std.ws.read(h)
|
function std.ws.read(h)
|
||||||
return std.ws_read(HTTP_REQUEST.id, h)
|
if not fcgio:is_ws() then return nil end
|
||||||
|
return fcgio:ws_read(h)
|
||||||
end
|
end
|
||||||
function std.ws.swrite(s)
|
function std.ws.t(...)
|
||||||
std.ws_t(HTTP_REQUEST.id, s)
|
if not fcgio:is_ws() then return nil end
|
||||||
|
fcgio:ws_send(false,...)
|
||||||
end
|
end
|
||||||
function std.ws.fwrite(s)
|
function std.ws.f(s)
|
||||||
std.ws_f(HTTP_REQUEST.id, s)
|
if not fcgio:is_ws() then return nil end
|
||||||
|
fcgio:send_file(s)
|
||||||
end
|
end
|
||||||
function std.ws.write_bytes(arr)
|
function std.ws.b(...)
|
||||||
std.ws_b(HTTP_REQUEST.id, arr)
|
if not fcgio:is_ws() then return nil end
|
||||||
|
fcgio:ws_send(true,...)
|
||||||
end
|
end
|
||||||
function std.ws.enable()
|
function std.ws.enable()
|
||||||
return HTTP_REQUEST ~= nil and HTTP_REQUEST.request["__web_socket__"] == "1"
|
return fcgio:is_ws()
|
||||||
end
|
end
|
||||||
function std.ws.close(code)
|
function std.ws.close(code)
|
||||||
std.ws_close(HTTP_REQUEST.id, code)
|
if not fcgio:is_ws() then return nil end
|
||||||
|
fcgio:ws_close(code)
|
||||||
end
|
end
|
||||||
std.ws.TEXT = 1
|
std.ws.TEXT = 1
|
||||||
std.ws.BIN = 2
|
std.ws.BIN = 2
|
||||||
|
Loading…
Reference in New Issue
Block a user