mirror of
https://git.shadowkat.net/izaya/tiny-gopherd.git
synced 2024-10-08 15:33:43 -04:00
made gopherd less CPU-heavy
This commit is contained in:
parent
6b058c1efa
commit
38d2478af0
11
gopherd.lua
11
gopherd.lua
@ -67,11 +67,12 @@ end
|
||||
local function handleConnect(client)
|
||||
client:settimeout(0)
|
||||
threads[pcount+1] = coroutine.create(function() local w,err = pcall(function()
|
||||
local host,port = client:getsockname()
|
||||
repeat
|
||||
coroutine.yield()
|
||||
line=client:receive()
|
||||
until line
|
||||
print(line)
|
||||
print(string.format("%s:%d: %s",host,port,line))
|
||||
local path,args = config.path .. cleanPath(line)
|
||||
local attr = fs.attributes(path)
|
||||
if attr then
|
||||
@ -121,17 +122,23 @@ local function handleConnect(client)
|
||||
end
|
||||
|
||||
local server = socket.bind("*",config.bindport)
|
||||
server:settimeout(config.timer)
|
||||
while true do -- totally not a scheduler
|
||||
client = server:accept()
|
||||
if client then
|
||||
server:settimeout(config.timer)
|
||||
handleConnect(client)
|
||||
end
|
||||
local c = 0
|
||||
for k,v in pairs(threads) do
|
||||
if coroutine.status(v) == "dead" then
|
||||
threads[k] = nil
|
||||
else
|
||||
coroutine.resume(v)
|
||||
c = c + 1
|
||||
end
|
||||
end
|
||||
if c == 0 then
|
||||
-- if there are no clients connected, make server:accept() block forever
|
||||
server:settimeout(inf)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user