diff --git a/OpenOS/usr/lib/net.lua b/OpenOS/usr/lib/net.lua index 2eb1c37..b57f790 100644 --- a/OpenOS/usr/lib/net.lua +++ b/OpenOS/usr/lib/net.lua @@ -113,7 +113,7 @@ end function net.listen(port) repeat _, from, rport, data = event.pull("net_msg") - until rport == port + until rport == port and data == "openstream" local nport = math.random(net.minport,net.maxport) local sclose = net.genPacketID() net.rsend(from,rport,tostring(nport)) @@ -121,4 +121,18 @@ function net.listen(port) return socket(from,nport,sclose) end +function net.flisten(port,listener) + local function helper(_,from,rport,data) + if rport == port and data == "openstream" then + local nport = math.random(net.minport,net.maxport) + local sclose = net.genPacketID() + net.rsend(from,rport,tostring(nport)) + net.rsend(from,nport,sclose) + listener(socket(from,nport,sclose)) + end + end + event.listen("net_msg",helper) + return helper +end + return net