Skip to content

Instantly share code, notes, and snippets.

@omarkj
Created March 2, 2011 19:00
Show Gist options
  • Save omarkj/851478 to your computer and use it in GitHub Desktop.
Save omarkj/851478 to your computer and use it in GitHub Desktop.
handle_cast(listen, #state{socket=Socket, rest=Rest} = State) ->
case gen_tcp:recv(Socket, 0, 35000) of
{ok, Data} ->
RestOfData = parse(<<Rest/binary, Data/binary>>),
gen_server:cast(?SERVER, listen),
State#state{rest=RestOfData};
{error, closed} ->
io:format("error, socket closed, do failover? ~n"),
gen_server:cast(?SERVER, connect),
failover(State);
{error, timeout} ->
io:format("error, timeout - failover ~n"),
gen_server:cast(?SERVER, connect),
failover(State);
_Other ->
io:format("listen - some other error :~p~n", [_Other]),
State
end,
{noreply, NewState};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment