added the net-ext library. pretty bare-bones atm but it'll be useful later. note to self: write documentation.

This commit is contained in:
Izaya 2017-08-02 23:52:52 +10:00
parent 581edc74a1
commit 07a9a3db3b
2 changed files with 24 additions and 0 deletions

View File

@ -11,6 +11,7 @@ modules/drivers/net.lua
modules/lib/readline.lua
modules/lib/shutil.lua
modules/lib/sha256.lua
modules/net/net-ext.lua
modules/applications/luash.lua
modules/applications/genkernel.lua
modules/applications/skex2.lua

23
modules/net/net-ext.lua Normal file
View File

@ -0,0 +1,23 @@
net.mtu = 256
function net.sendstring(addr,port,msg) -- for sending lots of data
net.send(addr,port,math.ceil(msg:len()/net.mtu))
for i = 1, #msg, net.mtu do
net.send(addr,port,msg:sub(i,(i+net.mtu)-1))
coroutine.yield()
coroutine.yield()
end
end
function net.recvstring(addr,port)
local fr,po,msg = ""
repeat
_,fr,po,msg = event.pull("net_msg")
until fr == addr and po == port
local ml,s = tonumber(msg), ""
for i = 1, ml do
_,fr,po,msg = event.pull("net_msg")
if fr == addr and po == port then
s=s..tostring(msg)
end
end
return s
end