Skip to content

Commit

Permalink
Make timing out operations (ezmq:term/2 and ezmq:recv/2) return call …
Browse files Browse the repository at this point in the history
…reference as well
  • Loading branch information
yrashk committed Mar 4, 2011
1 parent 172e311 commit 8e645a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/ezmq.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
-type ezmq_error_type() :: enotsup | eprotonosupport | enobufs | enetdown | eaddrinuse | eaddnotavail | econnrefused |
einprogress | efsm | enocompatproto | eterm | emthread | errno() | {unknown, integer()}.

-type ezmq_error() :: {error, ezmq_error_type()}.
-type ezmq_error() :: {error, ezmq_error_type()} | {error, timeout(), reference()}.

-type ezmq_data() :: iolist().

Expand Down
4 changes: 2 additions & 2 deletions src/ezmq.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ recv(Socket, Flags) when is_list(Flags) ->
{Ref, Result} ->
{ok, Result}
after Timeout ->
{error, timeout}
{error, timeout, Ref}
end;
Result ->
ezmq_result(Result)
Expand Down Expand Up @@ -98,7 +98,7 @@ term(Context, Timeout) ->
{Ref, Result} ->
Result
after Timeout ->
{error, timeout}
{error, timeout, Ref}
end;
Result ->
ezmq_result(Result)
Expand Down
8 changes: 5 additions & 3 deletions test/ezmq_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@ shutdown_no_blocking_test() ->
shutdown_blocking_test() ->
{ok, C} = ezmq:context(),
{ok, _S} = ezmq:socket(C, pub),
?assertEqual({error, timeout}, ezmq:term(C, 500)).
?assertMatch({error, timeout, _}, ezmq:term(C, 500)).

shutdown_blocking_unblocking_test() ->
{ok, C} = ezmq:context(),
{ok, S} = ezmq:socket(C, pub),
?assertEqual({error, timeout}, ezmq:term(C, 500)),
V = ezmq:term(C, 500),
?assertMatch({error, timeout, _}, V),
{error, timeout, Ref} = V,
ezmq:close(S),
receive
{R, ok} when is_reference(R) ->
{Ref, ok} ->
ok
end.

Expand Down

0 comments on commit 8e645a2

Please sign in to comment.