summaryrefslogtreecommitdiff
path: root/tests/modules/pipe/sched_echo_server.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-01 00:40:43 +0800
committerruki <[email protected]>2020-01-31 22:04:21 +0800
commit7fc59d939bd2cf426c9fb823a5a2616b0dd3b508 (patch)
tree1b3ab29f2255402a9ee3968baf10d1afa5b4c602 /tests/modules/pipe/sched_echo_server.lua
parent689afee096cb2a63233f8dcc3b7c161014b3c587 (diff)
update tbox and tests
Diffstat (limited to 'tests/modules/pipe/sched_echo_server.lua')
-rw-r--r--tests/modules/pipe/sched_echo_server.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/modules/pipe/sched_echo_server.lua b/tests/modules/pipe/sched_echo_server.lua
new file mode 100644
index 000000000..8da176c7e
--- /dev/null
+++ b/tests/modules/pipe/sched_echo_server.lua
@@ -0,0 +1,32 @@
+import("core.base.pipe")
+import("core.base.scheduler")
+
+function _session(id)
+
+ local pipefile = pipe.open("test" .. id, 'r')
+ if pipefile:connect() > 0 then
+ print("%s/%d: connected", pipefile, id)
+ local count = 0
+ local result = nil
+ while count < 10000 do
+ local read, data = pipefile:read(13, {block = true})
+ if read > 0 then
+ result = data
+ count = count + 1
+ else
+ break
+ end
+ end
+ print("%s/%d: read: %d, count: %d", pipefile, id, result and result:size() or 0, count)
+ result:dump()
+ end
+ pipefile:close()
+end
+
+function main(count)
+ count = count and tonumber(count) or 1
+ for i = 1, count do
+ scheduler.co_start(_session, i)
+ end
+ scheduler.runloop()
+end