Permalink
Browse files

R14B01 causes active receive to have problems. R14B02 works with acti…

…ve receive. Update test/comments based on testing.
  • Loading branch information...
1 parent 91b4e62 commit 788092e1f044cadfd2d0963d15eecb1d965c7093 @okeuday okeuday committed Mar 27, 2011
Showing with 36 additions and 9 deletions.
  1. +16 −8 c_src/erlzmq_nif.c
  2. +20 −1 test/erlzmq_test.erl
View
@@ -732,6 +732,8 @@ static void * polling_thread(void * handle)
r->data.recv.socket->socket_index),
enif_make_resource(r->data.recv.env, r->data.recv.socket)),
return_zmq_errno(r->data.recv.env, zmq_errno())));
+ enif_free_env(r->data.recv.env);
+ r->data.recv.env = enif_alloc_env();
item->revents = 0;
}
else {
@@ -756,6 +758,8 @@ static void * polling_thread(void * handle)
r->data.recv.socket->socket_index),
enif_make_resource(r->data.recv.env, r->data.recv.socket)),
enif_make_binary(r->data.recv.env, &binary)));
+ enif_free_env(r->data.recv.env);
+ r->data.recv.env = enif_alloc_env();
item->revents = 0;
}
else {
@@ -818,18 +822,18 @@ static void * polling_thread(void * handle)
erlzmq_thread_request_t * r =
(erlzmq_thread_request_t *) zmq_msg_data(&msg);
- if (r->type == ERLZMQ_THREAD_REQUEST_RECV) {
- zmq_pollitem_t item_zmq = {r->data.recv.socket->socket_zmq,
- 0, ZMQ_POLLIN, 0};
+ if (r->type == ERLZMQ_THREAD_REQUEST_SEND) {
+ zmq_pollitem_t item_zmq = {r->data.send.socket->socket_zmq,
+ 0, ZMQ_POLLOUT, 0};
status = vector_append(zmq_pollitem_t, &items_zmq, &item_zmq);
assert(status == 0);
status = vector_append(erlzmq_thread_request_t, &requests, r);
assert(status == 0);
zmq_msg_close(&msg);
}
- else if (r->type == ERLZMQ_THREAD_REQUEST_SEND) {
- zmq_pollitem_t item_zmq = {r->data.send.socket->socket_zmq,
- 0, ZMQ_POLLOUT, 0};
+ else if (r->type == ERLZMQ_THREAD_REQUEST_RECV) {
+ zmq_pollitem_t item_zmq = {r->data.recv.socket->socket_zmq,
+ 0, ZMQ_POLLIN, 0};
status = vector_append(zmq_pollitem_t, &items_zmq, &item_zmq);
assert(status == 0);
status = vector_append(erlzmq_thread_request_t, &requests, r);
@@ -844,11 +848,15 @@ static void * polling_thread(void * handle)
erlzmq_thread_request_t * r_old =
vector_get(erlzmq_thread_request_t, &requests, i);
if (r_old->type == ERLZMQ_THREAD_REQUEST_RECV) {
- enif_free_env(r_old->data.recv.env);
+ enif_clear_env(r_old->data.recv.env);
+ // FIXME
+ // causes crash on R14B01, works fine on R14B02
+ // (repeated enif_send with active receive broken on R14B01)
+ //enif_free_env(r_old->data.recv.env);
enif_release_resource(r_old->data.recv.socket);
}
else if (r_old->type == ERLZMQ_THREAD_REQUEST_SEND) {
- zmq_msg_close(&r_old->data.send.msg);
+ zmq_msg_close(&(r_old->data.send.msg));
enif_free_env(r_old->data.send.env);
enif_release_resource(r_old->data.send.socket);
}
View
@@ -145,6 +145,22 @@ ping_pong({S1, S2}, Msg, active) ->
1000 ->
?assertMatch({ok, Msg}, timeout)
end,
+ ok = erlzmq:send(S1, Msg),
+ receive
+ {zmq, S2, Msg} ->
+ ok
+ after
+ 1000 ->
+ ?assertMatch({ok, Msg}, timeout)
+ end,
+ ok = erlzmq:send(S2, Msg),
+ receive
+ {zmq, S1, Msg} ->
+ ok
+ after
+ 1000 ->
+ ?assertMatch({ok, Msg}, timeout)
+ end,
ok;
ping_pong({S1, S2}, Msg, passive) ->
ok = erlzmq:send(S1, Msg),
@@ -156,5 +172,8 @@ ping_pong({S1, S2}, Msg, passive) ->
basic_tests(Transport, Type1, Type2, Mode) ->
{ok, C} = erlzmq:context(1),
{S1, S2} = create_bound_pair(C, Type1, Type2, Mode, Transport),
- ping_pong({S1, S2}, <<"XXX">>, Mode).
+ ping_pong({S1, S2}, <<"XXX">>, Mode),
+ ok = erlzmq:close(S1),
+ ok = erlzmq:close(S2),
+ ok = erlzmq:term(C).

0 comments on commit 788092e

Please sign in to comment.