Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix. Supports `Pollable` objects by remove/modify methods. #14

Merged
merged 1 commit into from

3 participants

Alexey Melnichuk BuildHive Coveralls
Alexey Melnichuk
Owner

No description provided.

BuildHive

The ØMQ project » lzmq #19 SUCCESS
This pull request looks good
(what's this?)

Coveralls

Coverage Status

Coverage increased (+0.01%) when pulling 3e75c5c on moteus:master into 20548a7 on zeromq:master.

Alexey Melnichuk moteus merged commit 5dc2a70 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 3 deletions.
  1. +7 −3 src/lua/lzmq/poller.lua
  2. +8 −0 test/utest.lua
10 src/lua/lzmq/poller.lua
View
@@ -34,9 +34,13 @@ local Poller = zmq.poller
local poller_mt = {}
poller_mt.__index = poller_mt
+local function raw_socket(sock)
+ return (type(sock) == 'table') and (sock.socket) and sock:socket() or sock
+end
+
function poller_mt:add(sock, events, cb)
assert(cb ~= nil)
- local s = (type(sock) == 'table') and (sock.socket) and sock:socket() or sock
+ local s = raw_socket(sock)
local id = self.poller:add(s, events)
self.callbacks[id] = function(revents) return cb(sock, revents) end
end
@@ -44,7 +48,7 @@ end
function poller_mt:modify(sock, events, cb)
local id
if events ~= 0 and cb then
- id = self.poller:modify(sock, events)
+ id = self.poller:modify(raw_socket(sock), events)
self.callbacks[id] = function(revents) return cb(sock, revents) end
else
self:remove(sock)
@@ -52,7 +56,7 @@ function poller_mt:modify(sock, events, cb)
end
function poller_mt:remove(sock)
- local id = self.poller:remove(sock)
+ local id = self.poller:remove(raw_socket(sock))
assert(id <= #self.callbacks)
for i = id, #self.callbacks do
self.callbacks[i] = self.callbacks[i+1]
8 test/utest.lua
View
@@ -1604,6 +1604,14 @@ function test_pollable_interface()
ret = t[sub2] assert_table(ret) assert_equal("hello", ret[1]) assert_equal(false, ret[2])
ret = t[sub3] assert_table(ret) assert_equal("hello", ret[1]) assert_equal(false, ret[2])
+ poller:remove(sub2)
+
+ assert_true(pub:send("hello"))
+
+ assert_equal(2, poller:poll(100))
+
+ ret = t[sub1] assert_table(ret) assert_equal("hello", ret[1]) assert_equal(false, ret[2])
+ ret = t[sub3] assert_table(ret) assert_equal("hello", ret[1]) assert_equal(false, ret[2])
end
end
Something went wrong with that request. Please try again.