From c1604bae76f2a914658e314234ea1c939b62aea6 Mon Sep 17 00:00:00 2001 From: Garrett Smith Date: Thu, 9 Jun 2011 10:36:18 -0500 Subject: [PATCH] erlzmq:version/0 --- c_src/erlzmq_nif.c | 13 ++++++++++++- src/erlzmq.erl | 8 +++++++- src/erlzmq_nif.erl | 6 +++++- test/erlzmq_test.erl | 3 +++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/c_src/erlzmq_nif.c b/c_src/erlzmq_nif.c index 0f4bfa7..d20a980 100644 --- a/c_src/erlzmq_nif.c +++ b/c_src/erlzmq_nif.c @@ -105,6 +105,7 @@ NIF(erlzmq_nif_send); NIF(erlzmq_nif_recv); NIF(erlzmq_nif_close); NIF(erlzmq_nif_term); +NIF(erlzmq_nif_version); static void * polling_thread(void * handle); static ERL_NIF_TERM add_active_req(ErlNifEnv* env, erlzmq_socket_t * socket); @@ -121,7 +122,8 @@ static ErlNifFunc nif_funcs[] = {"send", 3, erlzmq_nif_send}, {"recv", 2, erlzmq_nif_recv}, {"close", 1, erlzmq_nif_close}, - {"term", 1, erlzmq_nif_term} + {"term", 1, erlzmq_nif_term}, + {"version", 0, erlzmq_nif_version} }; NIF(erlzmq_nif_context) @@ -709,6 +711,15 @@ NIF(erlzmq_nif_term) } } +NIF(erlzmq_nif_version) +{ + int major, minor, patch; + zmq_version(&major, &minor, &patch); + return enif_make_tuple3(env, enif_make_int(env, major), + enif_make_int(env, minor), + enif_make_int(env, patch)); +} + static void * polling_thread(void * handle) { erlzmq_context_t * context = (erlzmq_context_t *) handle; diff --git a/src/erlzmq.erl b/src/erlzmq.erl index cd144b3..39efdc3 100644 --- a/src/erlzmq.erl +++ b/src/erlzmq.erl @@ -38,7 +38,8 @@ close/1, close/2, term/1, - term/2]). + term/2, + version/0]). -export_type([erlzmq_socket/0, erlzmq_context/0]). %% @equiv context(1) @@ -291,6 +292,11 @@ term(Context, Timeout) -> Result end. +%% @doc Returns the 0MQ library version. +%% @end +-spec version() -> {integer(), integer(), integer()}. + +version() -> erlzmq_nif:version(). %% Private diff --git a/src/erlzmq_nif.erl b/src/erlzmq_nif.erl index 2e9907e..f38ae9a 100644 --- a/src/erlzmq_nif.erl +++ b/src/erlzmq_nif.erl @@ -10,7 +10,8 @@ setsockopt/3, getsockopt/2, close/1, - term/1]). + term/1, + version/0]). -on_load(init/0). @@ -62,3 +63,6 @@ close(_Socket) -> term(_Context) -> erlang:nif_error(not_loaded). + +version() -> + erlang:nif_error(not_loaded). diff --git a/test/erlzmq_test.erl b/test/erlzmq_test.erl index 03d4dbb..8a91d8b 100644 --- a/test/erlzmq_test.erl +++ b/test/erlzmq_test.erl @@ -58,6 +58,9 @@ reqrep_tcp_test() -> shutdown_stress_test() -> ?assertMatch(ok, shutdown_stress_loop(10)). +version_test() -> + ?assertEqual({2, 1, 7}, erlzmq:version()). + shutdown_stress_loop(0) -> ok; shutdown_stress_loop(N) ->