Skip to content

Commit

Permalink
Work on object collection
Browse files Browse the repository at this point in the history
Adding __gc for socket objecs
Adding NULL pointer check to context:term and socket:close
  • Loading branch information
jsimmons authored and iamaleksey committed Aug 15, 2010
1 parent c47515a commit 08c18e8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions zmq.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ static int Lzmq_init(lua_State *L)
static int Lzmq_term(lua_State *L)
{
zmq_ptr *ctx = luaL_checkudata(L, 1, MT_ZMQ_CONTEXT);
assert(zmq_term(ctx->ptr) == 0);

if(ctx->ptr != NULL) {
assert(zmq_term(ctx->ptr) == 0);
ctx->ptr = NULL;
}

return 0;
}

Expand All @@ -103,7 +108,12 @@ static int Lzmq_socket(lua_State *L)
static int Lzmq_close(lua_State *L)
{
zmq_ptr *s = luaL_checkudata(L, 1, MT_ZMQ_SOCKET);
assert(zmq_close(s->ptr) == 0);

if(s->ptr != NULL) {
assert(zmq_close(s->ptr) == 0);
s->ptr = NULL;
}

return 0;
}

Expand Down Expand Up @@ -311,6 +321,7 @@ static const luaL_reg ctxmethods[] = {
};

static const luaL_reg sockmethods[] = {
{"__gc", Lzmq_close},
{"close", Lzmq_close},
{"setopt", Lzmq_setsockopt},
{"getopt", Lzmq_getsockopt},
Expand Down

0 comments on commit 08c18e8

Please sign in to comment.