|
|
@@ -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 |