From e891f0d2208dce4348cbbe93b697411fbf5e7c81 Mon Sep 17 00:00:00 2001 From: Izaya Date: Sat, 17 Feb 2018 18:31:50 +1100 Subject: [PATCH] made listen and flisten care what is sent to them --- OpenOS/usr/lib/net.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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