37 lines
698 B
Plaintext
37 lines
698 B
Plaintext
cqueues = require "cqueues"
|
|
url = require "net.url"
|
|
|
|
class Server
|
|
new: (hdlr) =>
|
|
@cq = cqueues.new!
|
|
@hdlr = hdlr
|
|
|
|
attach: (cq) =>
|
|
cq\wrap ->
|
|
@cq\loop!
|
|
|
|
listen: (srv) =>
|
|
@cq\wrap ->
|
|
for conn in srv\clients!
|
|
@cq\wrap ->
|
|
with conn
|
|
_, ip = \peername!
|
|
pid, uid, gid = \peerpid!, \peereid!
|
|
request = \read "*l"
|
|
\shutdown "r"
|
|
u = url.parse request
|
|
ctx =
|
|
:ip
|
|
:pid
|
|
:uid
|
|
:gid
|
|
host: u.host
|
|
path: u.path
|
|
query: u.query
|
|
@hdlr\serve ctx, conn
|
|
\close!
|
|
|
|
{
|
|
:Server
|
|
}
|