Changed case for low-level poller object.

pull/10/head
Robert G. Jakabosky 15 years ago
parent 86f2d0c027
commit 6126e4a0d6

@ -19,7 +19,7 @@
-- THE SOFTWARE. -- THE SOFTWARE.
-- --
-- zmq.poller wraps the low-level zmq.zmq_poller object. -- zmq.poller wraps the low-level zmq.ZMQ_Poller object.
-- --
-- This wrapper simplifies the event polling loop. -- This wrapper simplifies the event polling loop.
-- --
@ -87,7 +87,7 @@ module(...)
function new(pre_alloc) function new(pre_alloc)
return setmetatable({ return setmetatable({
poller = zmq.zmq_poller(pre_alloc), poller = zmq.ZMQ_Poller(pre_alloc),
callbacks = setmetatable({}, {__mode="k"}), callbacks = setmetatable({}, {__mode="k"}),
}, poller_mt) }, poller_mt)
end end

@ -18,26 +18,26 @@
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE. -- THE SOFTWARE.
local zmq_poller_type = [[ local ZMQ_Poller_type = [[
typedef struct zmq_poller { typedef struct ZMQ_Poller {
zmq_pollitem_t *items; zmq_pollitem_t *items;
int next; int next;
int count; int count;
int free_list; int free_list;
int len; int len;
} zmq_poller; } ZMQ_Poller;
]] ]]
object "zmq_poller" { object "ZMQ_Poller" {
-- store the `zmq_poller` structure in Lua userdata object -- store the `ZMQ_Poller` structure in Lua userdata object
userdata_type = "embed", userdata_type = "embed",
c_source(zmq_poller_type), c_source(ZMQ_Poller_type),
c_source[[ c_source[[
#define FREE_ITEM_EVENTS_TAG 0xFFFF #define FREE_ITEM_EVENTS_TAG 0xFFFF
#define ITEM_TO_INDEX(items, item) (item - (items)) #define ITEM_TO_INDEX(items, item) (item - (items))
static int poller_resize_items(zmq_poller *this, int len) { static int poller_resize_items(ZMQ_Poller *this, int len) {
int old_len = this->len; int old_len = this->len;
/* make sure new length is atleast as large as items count. */ /* make sure new length is atleast as large as items count. */
@ -55,7 +55,7 @@ static int poller_resize_items(zmq_poller *this, int len) {
return len; return len;
} }
static int poller_find_sock_item(zmq_poller *this, ZMQ_Socket *sock) { static int poller_find_sock_item(ZMQ_Poller *this, ZMQ_Socket *sock) {
zmq_pollitem_t *items; zmq_pollitem_t *items;
int count; int count;
int n; int n;
@ -70,7 +70,7 @@ static int poller_find_sock_item(zmq_poller *this, ZMQ_Socket *sock) {
return -1; return -1;
} }
static int poller_find_fd_item(zmq_poller *this, socket_t fd) { static int poller_find_fd_item(ZMQ_Poller *this, socket_t fd) {
zmq_pollitem_t *items; zmq_pollitem_t *items;
int count; int count;
int n; int n;
@ -85,7 +85,7 @@ static int poller_find_fd_item(zmq_poller *this, socket_t fd) {
return -1; return -1;
} }
static void poller_remove_item(zmq_poller *this, int idx) { static void poller_remove_item(ZMQ_Poller *this, int idx) {
zmq_pollitem_t *items; zmq_pollitem_t *items;
int free_list; int free_list;
int count; int count;
@ -110,7 +110,7 @@ static void poller_remove_item(zmq_poller *this, int idx) {
items[idx].events = FREE_ITEM_EVENTS_TAG; items[idx].events = FREE_ITEM_EVENTS_TAG;
} }
static int poller_get_free_item(zmq_poller *this) { static int poller_get_free_item(ZMQ_Poller *this) {
zmq_pollitem_t *curr; zmq_pollitem_t *curr;
zmq_pollitem_t *next; zmq_pollitem_t *next;
int count; int count;
@ -147,7 +147,7 @@ static int poller_get_free_item(zmq_poller *this) {
return idx; return idx;
} }
static int poller_compact_items(zmq_poller *this) { static int poller_compact_items(ZMQ_Poller *this) {
zmq_pollitem_t *items; zmq_pollitem_t *items;
int count; int count;
int old_count; int old_count;
@ -186,7 +186,7 @@ static int poller_compact_items(zmq_poller *this) {
return count; return count;
} }
static int poller_poll(zmq_poller *this, long timeout) { static int poller_poll(ZMQ_Poller *this, long timeout) {
int count; int count;
/* remove free slots from items list. */ /* remove free slots from items list. */
count = poller_compact_items(this); count = poller_compact_items(this);
@ -195,13 +195,13 @@ static int poller_poll(zmq_poller *this, long timeout) {
} }
]], ]],
ffi_export_function "int" "poller_find_sock_item" "(zmq_poller *this, ZMQ_Socket *sock)", ffi_export_function "int" "poller_find_sock_item" "(ZMQ_Poller *this, ZMQ_Socket *sock)",
ffi_export_function "int" "poller_find_fd_item" "(zmq_poller *this, socket_t fd)", ffi_export_function "int" "poller_find_fd_item" "(ZMQ_Poller *this, socket_t fd)",
ffi_export_function "int" "poller_get_free_item" "(zmq_poller *this)", ffi_export_function "int" "poller_get_free_item" "(ZMQ_Poller *this)",
ffi_export_function "int" "poller_poll" "(zmq_poller *this, long timeout)", ffi_export_function "int" "poller_poll" "(ZMQ_Poller *this, long timeout)",
ffi_export_function "void" "poller_remove_item" "(zmq_poller *this, int idx)", ffi_export_function "void" "poller_remove_item" "(ZMQ_Poller *this, int idx)",
-- --
-- Define zmq_poller type & function API for FFI -- Define ZMQ_Poller type & function API for FFI
-- --
ffi_cdef[[ ffi_cdef[[
typedef struct zmq_pollitem_t { typedef struct zmq_pollitem_t {
@ -213,12 +213,12 @@ typedef struct zmq_pollitem_t {
int zmq_poll(zmq_pollitem_t *items, int nitems, long timeout); int zmq_poll(zmq_pollitem_t *items, int nitems, long timeout);
]], ]],
ffi_cdef(zmq_poller_type), ffi_cdef(ZMQ_Poller_type),
constructor "new" { constructor "new" {
var_in{ "unsigned int", "length", is_optional = true, default = 10 }, var_in{ "unsigned int", "length", is_optional = true, default = 10 },
c_source[[ c_source[[
zmq_poller poller; ZMQ_Poller poller;
${this} = &poller; ${this} = &poller;
${this}->items = (zmq_pollitem_t *)calloc(${length}, sizeof(zmq_pollitem_t)); ${this}->items = (zmq_pollitem_t *)calloc(${length}, sizeof(zmq_pollitem_t));
${this}->next = -1; ${this}->next = -1;

Loading…
Cancel
Save