gen_tcp:recv() and client_machine_crash

Christian S chsu79@REDACTED
Mon Jun 26 21:51:52 CEST 2006

On 6/26/06, HP Wei <hp@REDACTED> wrote:
> handle_request(Sock) ->
>    case gen_tcp:recv(Sock, 0) of
>      {ok, Bin} ->
>          handle_Bin(...);
>      {error, Reason} ->
>          handle_exit(...)
>    end.

> I want the handle_exit() to handle three abnormal-exit situations
> that may occur on the client side.
> (1) the client's code gets Control_C exit;
> (2) the client's code gets killed by 'kill -9 pid'
>     [ under UNIX ];
> (3) the machine that the client is running on
>     crashes !

When the process dies as in 1 and 2, the OS will be so kind as to
politely inform socket peers that the connection should be removed.
When the OS itself has died, there is nothing to inform the peer about
it. My suggestion is that you use timeouts. See the optional third
argument to recv.

More information about the erlang-questions mailing list