Skip to content

Instantly share code, notes, and snippets.

@evax
Created March 3, 2011 18:44
Show Gist options
  • Save evax/853259 to your computer and use it in GitHub Desktop.
Save evax/853259 to your computer and use it in GitHub Desktop.
-module(ezmq_test).
-export([hwm/0]).
hwm() ->
{ok, C} = ezmq:context(),
{ok, S1} = ezmq:socket(C, pull),
{ok, S2} = ezmq:socket(C, push),
ok = ezmq:setsockopt(S2, linger, 0),
ok = ezmq:setsockopt(S2, hwm, 5),
ok = ezmq:bind(S1, "tcp://127.0.0.1:5858"),
ok = ezmq:connect(S2, "tcp://127.0.0.1:5858"),
ok = hwm_loop(10, S2),
{ok, <<"test">>} = ezmq:recv(S1),
ok = ezmq:send(S2, <<"test">>).
hwm_loop(0, _S) ->
ok;
hwm_loop(N, S) when N > 5 ->
ok = ezmq:send(S, <<"test">>, [noblock]),
hwm_loop(N-1, S);
hwm_loop(N, S) ->
{error, _Error} = ezmq:send(S, <<"test">>, [noblock]),
hwm_loop(N-1, S).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment