Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Couple asserts upgraded to handled errors #16

Merged
merged 3 commits into from Jun 12, 2011
View
@@ -136,7 +136,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);
@@ -195,7 +197,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
@@ -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)).