-
-
Save metacoma/c34fed40a58eb9058bc7eb95b17ba2d4 to your computer and use it in GitHub Desktop.
kvik_rfc-hel.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
np = require 'libs.9p' | |
pprint = require 'libs.pprint' | |
require 'libs.readdir' | |
serpent = require 'serpent' | |
local data = require 'data' | |
local socket = require 'socket' | |
local tcp = assert(socket.tcp()) | |
local s, err = tcp:connect('dum.a-b.xyz', 905) | |
if not s then | |
error(err) | |
end | |
local buf_stats = 0 | |
local total_stats = 0 | |
local conn = np.newconn(function(size) | |
local size, err = tcp:receive(size) | |
if err then | |
error(err) | |
end | |
return size | |
end, function(buf) | |
tcp:send(buf) | |
end) | |
conn:attach("root", "") | |
local f = conn:newfid() | |
conn:walk(conn.rootfid, f, "./") | |
conn:open(f, 0) | |
local offset = 0 | |
local buf_size = 9000 | |
while offset ~= -1 do | |
buf_stats = 0 | |
local read_data = conn:read(f, offset, buf_size) | |
local dir = tostring(read_data) | |
if (read_data == nil) then | |
print("Everything was read") | |
offset = -1 | |
else | |
offset = offset + #(tostring(read_data)) | |
print(#dir) | |
end | |
while offset ~= -1 do | |
local st = conn:getstat(data.new(dir)) | |
if st == nil then | |
print("Out of stats") | |
return nil | |
end | |
buf_stats = buf_stats + 1 | |
total_stats = total_stats + 1 | |
--print(serpent.line(st)) | |
dir = dir:sub(st.size + 3) | |
if (#dir == 0) then | |
print("End of current read buffer. Stats parsed: " .. buf_stats .. ". Till now proceeded " .. total_stats .. " stats.") | |
break | |
end | |
end | |
end | |
print(total_stats) | |
print(#(readdir(conn, "./"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment