From 565d7e6bcbbdb6b98e1bed02b3ce1fe6ac7b1994 Mon Sep 17 00:00:00 2001 From: Alexander Gall Date: Sat, 22 Dec 2018 13:52:49 +0100 Subject: [PATCH] apps.basic: apply link push methods to basic apps --- src/apps/basic/basic_apps.lua | 58 +++++++++++++++-------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/src/apps/basic/basic_apps.lua b/src/apps/basic/basic_apps.lua index a7fb8fa9da..7813b21de2 100644 --- a/src/apps/basic/basic_apps.lua +++ b/src/apps/basic/basic_apps.lua @@ -39,11 +39,9 @@ function Join:new() return setmetatable({}, {__index=Join}) end -function Join:push () - for _, inport in ipairs(self.input) do - while not link.empty(inport) do - transmit(self.output.output, receive(inport)) - end +function Join:push (i) + while not link.empty(i) do + transmit(self.output.output, receive(i)) end end @@ -57,12 +55,10 @@ function Split:new () return setmetatable({}, {__index=Split}) end -function Split:push () - for _, i in ipairs(self.input) do - for _, o in ipairs(self.output) do - for _ = 1, link.nreadable(i) do - transmit(o, receive(i)) - end +function Split:push (i) + for _, o in ipairs(self.output) do + for _ = 1, link.nreadable(i) do + transmit(o, receive(i)) end end end @@ -75,12 +71,10 @@ function Sink:new () return setmetatable({}, {__index=Sink}) end -function Sink:push () - for _, i in ipairs(self.input) do - for _ = 1, link.nreadable(i) do - local p = receive(i) - packet.free(p) - end +function Sink:push (i) + for _ = 1, link.nreadable(i) do + local p = receive(i) + packet.free(p) end end @@ -92,16 +86,14 @@ function Tee:new () return setmetatable({}, {__index=Tee}) end -function Tee:push () +function Tee:push (i) local noutputs = #self.output if noutputs > 0 then - for _, i in ipairs(self.input) do - for _ = 1, link.nreadable(i) do - local p = receive(i) - do local output = self.output - for k = 1, #output do - transmit(output[k], k == #output and p or packet.clone(p)) - end + for _ = 1, link.nreadable(i) do + local p = receive(i) + do local output = self.output + for k = 1, #output do + transmit(output[k], k == #output and p or packet.clone(p)) end end end @@ -117,8 +109,8 @@ function Repeater:new () {__index=Repeater}) end -function Repeater:push () - local i, o = self.input.input, self.output.output +function Repeater:push (i) + local o = self.output.output for _ = 1, link.nreadable(i) do local p = receive(i) table.insert(self.packets, p) @@ -147,9 +139,9 @@ function Truncate:new (n) return setmetatable({n = n}, {__index=Truncate}) end -function Truncate:push () - for _ = 1, link.nreadable(self.input.input) do - local p = receive(self.input.input) +function Truncate:push (i) + for _ = 1, link.nreadable(i) do + local p = receive(i) ffi.fill(p.data, math.min(0, self.n - p.length)) p.length = self.n transmit(self.output.output,p) @@ -164,9 +156,9 @@ function Sample:new (n) return setmetatable({n = n, seen = 1}, {__index=Sample}) end -function Sample:push () - for _ = 1, link.nreadable(self.input.input) do - local p = receive(self.input.input) +function Sample:push (i) + for _ = 1, link.nreadable(i) do + local p = receive(i) if self.n == self.seen then transmit(self.output.output, p) self.seen = 1