Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erlzmq:version/0 #15

Merged
merged 2 commits into from
Jun 12, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion c_src/erlzmq_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/erlzmq.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/erlzmq_nif.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
setsockopt/3,
getsockopt/2,
close/1,
term/1]).
term/1,
version/0]).

-on_load(init/0).

Expand Down Expand Up @@ -62,3 +63,6 @@ close(_Socket) ->

term(_Context) ->
erlang:nif_error(not_loaded).

version() ->
erlang:nif_error(not_loaded).
3 changes: 3 additions & 0 deletions test/erlzmq_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ reqrep_tcp_test() ->
shutdown_stress_test() ->
?assertMatch(ok, shutdown_stress_loop(10)).

version_test() ->
?assertEqual({2, 1, 7}, erlzmq:version()).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this particular test is a good idea, at least while implemented in this particular way

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A greater than test might make sense, could be turned into an int I guess

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather test the return format.


shutdown_stress_loop(0) ->
ok;
shutdown_stress_loop(N) ->
Expand Down