mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-12 14:09:12 +00:00
add websockets echo server to redbean-tester
This commit is contained in:
parent
8f4dc5a2af
commit
ecb47384f8
2 changed files with 39 additions and 0 deletions
|
@ -71,11 +71,17 @@ o/$(MODE)/test/tool/net/%.dbg: \
|
||||||
$(APE_NO_MODIFY_SELF)
|
$(APE_NO_MODIFY_SELF)
|
||||||
@$(APELINK)
|
@$(APELINK)
|
||||||
|
|
||||||
|
|
||||||
|
o/$(MODE)/tool/net/tester/.init.lua.zip.o: private \
|
||||||
|
ZIPOBJ_FLAGS += \
|
||||||
|
-B
|
||||||
|
|
||||||
.PRECIOUS: o/$(MODE)/test/tool/net/redbean-tester
|
.PRECIOUS: o/$(MODE)/test/tool/net/redbean-tester
|
||||||
o/$(MODE)/test/tool/net/redbean-tester.dbg: \
|
o/$(MODE)/test/tool/net/redbean-tester.dbg: \
|
||||||
$(TOOL_NET_DEPS) \
|
$(TOOL_NET_DEPS) \
|
||||||
o/$(MODE)/tool/net/redbean.o \
|
o/$(MODE)/tool/net/redbean.o \
|
||||||
$(TOOL_NET_REDBEAN_LUA_MODULES) \
|
$(TOOL_NET_REDBEAN_LUA_MODULES) \
|
||||||
|
o/$(MODE)/tool/net/tester/.init.lua.zip.o \
|
||||||
o/$(MODE)/tool/net/demo/seekable.txt.zip.o \
|
o/$(MODE)/tool/net/demo/seekable.txt.zip.o \
|
||||||
o/$(MODE)/tool/net/net.pkg \
|
o/$(MODE)/tool/net/net.pkg \
|
||||||
$(CRT) \
|
$(CRT) \
|
||||||
|
|
33
tool/net/tester/.init.lua
Normal file
33
tool/net/tester/.init.lua
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
-- special script called by main redbean process at startup
|
||||||
|
HidePath('/usr/share/zoneinfo/')
|
||||||
|
HidePath('/usr/share/ssl/')
|
||||||
|
|
||||||
|
-- 20Ki, for certain autobahn tests
|
||||||
|
ProgramMaxPayloadSize(20 * 1024 * 1024)
|
||||||
|
|
||||||
|
function OnHttpRequest()
|
||||||
|
if GetPath() == "/ws" then
|
||||||
|
ws.Write(nil) -- upgrade without sending a response
|
||||||
|
coroutine.yield()
|
||||||
|
|
||||||
|
local fds = {[GetClientFd()] = unix.POLLIN}
|
||||||
|
-- simple echo server
|
||||||
|
while true do
|
||||||
|
unix.poll(fds)
|
||||||
|
local s, t = ws.Read()
|
||||||
|
if t == ws.CLOSE then
|
||||||
|
return
|
||||||
|
elseif t == ws.TEXT then
|
||||||
|
ws.Write(s, ws.TEXT)
|
||||||
|
coroutine.yield()
|
||||||
|
elseif t == ws.BIN then
|
||||||
|
ws.Write(s, ws.BIN)
|
||||||
|
coroutine.yield()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Route()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue