Permalink
Browse files

Merge pull request #16 from gar1t/robustify

Couple asserts upgraded to handled errors
  • Loading branch information...
2 parents fda1273 + 628af0c commit 152e21836783eb6b63edcc1b233a0d04f4a3361a @yrashk yrashk committed Jun 12, 2011
Showing with 9 additions and 2 deletions.
  1. +6 −2 c_src/erlzmq_nif.c
  2. +3 −0 test/erlzmq_test.erl
View
8 c_src/erlzmq_nif.c
@@ -138,7 +138,9 @@ NIF(erlzmq_nif_context)
sizeof(erlzmq_context_t));
assert(context);
context->context_zmq = zmq_init(thread_count);
- assert(context->context_zmq);
+ if (!context->context_zmq) {
+ return return_zmq_errno(env, zmq_errno());
+ }
char thread_socket_id[64];
sprintf(thread_socket_id, "inproc://erlzmq-%ld", (long int) context);
@@ -197,7 +199,9 @@ NIF(erlzmq_nif_socket)
socket->context = context;
socket->socket_index = context->socket_index++;
socket->socket_zmq = zmq_socket(context->context_zmq, socket_type);
- assert(socket->socket_zmq);
+ if (!socket->socket_zmq) {
+ return return_zmq_errno(env, zmq_errno());
+ }
socket->active = active;
socket->mutex = enif_mutex_create("erlzmq_socket_t_mutex");
assert(socket->mutex);
View
3 test/erlzmq_test.erl
@@ -55,6 +55,9 @@ reqrep_tcp_test() ->
basic_tests("tcp://127.0.0.1:5556", req, rep, active),
basic_tests("tcp://127.0.0.1:5557", req, rep, passive).
+bad_init_test() ->
+ ?assertEqual({error, einval}, erlzmq:context(-1)).
+
shutdown_stress_test() ->
?assertMatch(ok, shutdown_stress_loop(10)).

0 comments on commit 152e218

Please sign in to comment.