代码拉取完成,页面将自动刷新
同步操作将从 fulinux/lua 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/lua
local socket = require("socket")
function receive (connection)
connection:settimeout(0)
local s, status, partial = connection:receive(1024)
if status == "timeout" then
coroutine.yield(connection)
end
return s or partial, status
end
function download (host, file)
-- 创建一个 TCP 连接,连接到 HTTP 连接的标准端口 -- 80 端口上
local sock = assert(socket.connect(host, 80))
local count = 0
sock:send("GET " .. file .. " HTTP/1.0\r\n\r\n")
while true do
-- 以 1K 的字节块来接收数据,并把接收到字节块输出来
local s, status, partial = sock:receive(1024)
count = count + #(s or partial)
if status == "closed" then break end
end
sock:close()
print(file, count)
end
threads = {}
function get (host, file)
local co = coroutine.create(function()
download(host, file)
end)
table.insert(threads, co)
end
function dispatch ()
local i = 1
local connections = {}
while true do
if threads[i] == nil then
if threads[1] == nil then break end
i = 1
connections = {}
end
local status, res = coroutine.resume(threads[i])
if not res then
table.remove(threads, i)
else
i = i + 1
connections[#connections + 1] = res
if #connections == #threads then
socket.select(connections)
end
end
end
end
host = "www.w3.org"
get(host, "/TR/html401/html40.txt")
get(host, "/TR/2002/REC-xhtml1-20020801/xhtml1.pdf")
get(host, "/TR/REC-html32.html")
get(host, "/TR/2000/REC-DOM-Level-2-Core-20001113/DOM2-Core.txt")
dispatch() -- main loop
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。