Permalink
Browse files

server_sent_events: end gen_server process if send fails

  • Loading branch information...
1 parent 6c6f62f commit 2ad166aa24ad3b5ce73f76223fb96e968539842d @vinoski vinoski committed Jul 12, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 examples/src/server_sent_events.erl
@@ -61,8 +61,14 @@ handle_info({discard, _YawsPid}, State) ->
handle_info(tick, #state{sock=Socket}=State) ->
Time = erlang:localtime(),
Data = yaws_sse:data(httpd_util:rfc1123_date(Time)),
- yaws_sse:send_events(Socket, Data),
- {noreply, State};
+ case yaws_sse:send_events(Socket, Data) of
+ ok ->
+ {noreply, State};
+ {error, closed} ->
+ {stop, normal, State};
+ {error, Reason} ->
+ {stop, Reason, State}
+ end;
handle_info({tcp_closed, _}, State) ->
{stop, normal, State#state{sock=closed}};
handle_info(_Info, State) ->

0 comments on commit 2ad166a

Please sign in to comment.