make the gemini server have its own cqueue

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2021-05-10 14:31:13 +00:00
parent d5dfe68ad6
commit 3f1df57558
2 changed files with 13 additions and 6 deletions

View File

@ -1,10 +1,15 @@
cqueues = require "cqueues"
url = require "net.url" url = require "net.url"
class Server class Server
new: (cq, hdlr) => new: (hdlr) =>
@cq = cq @cq = cqueues.new!
@hdlr = hdlr @hdlr = hdlr
attach: (cq) =>
cq\wrap ->
@cq\loop!
listen: (srv) => listen: (srv) =>
@cq\wrap -> @cq\wrap ->
for conn in srv\clients! for conn in srv\clients!
@ -12,6 +17,7 @@ class Server
with conn with conn
_, ip = \peername! _, ip = \peername!
request = \read "*l" request = \read "*l"
\shutdown "r"
u = url.parse request u = url.parse request
ctx = ctx =
:ip :ip

View File

@ -11,10 +11,11 @@ class ProxyRequestRefusedHandler
conn\write "53 Proxy request refused \r\n" conn\write "53 Proxy request refused \r\n"
ln.log ctx, {status: 53} ln.log ctx, {status: 53}
with gemini.Server cq, ProxyRequestRefusedHandler! with gemini.Server ProxyRequestRefusedHandler!
\listen socket.listen "127.0.0.1", "58816" \listen socket.listen "127.0.0.1", "58816"
\listen socket.listen -- \listen socket.listen
path: "./var/mipha.sock" -- path: "./var/mipha.sock"
unlink: true -- unlink: true
\attach cq
assert cq\loop! assert cq\loop!