summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Kendrick (humdrum) <rjek@rjek.com>2013-09-10 17:48:50 +0100
committerRob Kendrick (humdrum) <rjek@rjek.com>2013-09-10 17:48:50 +0100
commit44c3d7e8cdef51b7e630d38015da9b571a07e526 (patch)
tree820824f5fb985530255c405fcf912e0b67473455
parentbf1f131ed76fa0d3e6da94d99821c074212b7215 (diff)
downloadluxio-44c3d7e8cdef51b7e630d38015da9b571a07e526.tar.gz
Add trivial examples of simple mq layer, fix simple mq layer for recent mq changes
-rwxr-xr-xexamples/mq-read.lua22
-rwxr-xr-xexamples/mq-write.lua14
-rw-r--r--luxio/mq.lua6
3 files changed, 39 insertions, 3 deletions
diff --git a/examples/mq-read.lua b/examples/mq-read.lua
new file mode 100755
index 0000000..3b3703b
--- /dev/null
+++ b/examples/mq-read.lua
@@ -0,0 +1,22 @@
+#!/usr/bin/lua
+
+local sio = require "luxio.simple"
+local mq = require "luxio.mq"
+
+h = mq.open("/luxio-mq", "r", sio.tomode "0777")
+
+print(h)
+
+while true do
+ local msg = assert(h:pull())
+ for k, v in pairs(msg) do
+ print(k, v)
+ end
+
+ if msg.die then
+ h:close()
+ mq.unlink "/luxio-mq"
+ os.exit()
+ end
+end
+
diff --git a/examples/mq-write.lua b/examples/mq-write.lua
new file mode 100755
index 0000000..0a243fd
--- /dev/null
+++ b/examples/mq-write.lua
@@ -0,0 +1,14 @@
+#!/usr/bin/lua
+
+local sio = require "luxio.simple"
+local mq = require "luxio.mq"
+
+h = mq.open("/luxio-mq", "w", sio.tomode "0777")
+
+print(h)
+
+h:push { cat = "meow", dog = "woof", horse = "neigh", webmonkey = "AJAX!" }
+h:push { die = true }
+
+h:close()
+
diff --git a/luxio/mq.lua b/luxio/mq.lua
index 4ba8c65..6e11f8d 100644
--- a/luxio/mq.lua
+++ b/luxio/mq.lua
@@ -101,8 +101,8 @@ local mq_mt = {
end,
__tostring = function(x)
- return ("message queue: %s %s (%d)%s"):format(
- x.rw_mode, x.path, x.desc, x.closed and " closed" or "")
+ return ("message queue: %s %s (%s)%s"):format(
+ x.rw_mode, x.path, tostring(x.desc), x.closed and " closed" or "")
end,
__gc = mq_meta_gc
@@ -155,7 +155,7 @@ local function open(path, rw, mode)
mq, errno = l.mq_open(path, rw_mode)
end
- if mq < 0 then
+ if type(mq) == "number" and mq == -1 then
return err("mq_open", errno)
end