[erlang-questions] gen_fsm and keepalive timer
Dmitry Kolesnikov
dmkolesnikov@REDACTED
Sat Dec 31 17:14:19 CET 2011
Hello,
I would recommend to use gen_fsm:send_event_after(...)
see http://www.erlang.org/doc/man/gen_fsm.html
It makes your code is more readable and allow to handle multiple timeouts/timers within state.
Dmitry
On 29.12.2011, at 20.35, Michael Santos <michael.santos@REDACTED> wrote:
> On Thu, Dec 29, 2011 at 06:51:44PM +0100, Ivan Ostres wrote:
>> Hi all!
>>
>> I am trying to implement FSM of a protocol inside gen_fsm behavior.
>> For a keepalive purpose I need a timer that would produce event when
>> timer is expired so I could know when to send a keepalive packet and
>> to know when holdtime is gone (I didn;t receive keepalive packet
>> from other side). I was trying to get more info on
>> gen_fsm:start_timer but documentation is a bit sparse - it's clear
>> how to create timer but not how to catch it's event (well, at least
>> to me since this is first time I am using gen_fsm).
>>
>> If someone could explain this in few sentences I would be very
>> grateful. Also if there is a better way for keepalive mechanism
>> inside gen_fsm, I would like to know it.
>>
>> Thanks and regards,
>> Ivan Ostres
>
> Using the optional timeout in gen_fsm states might be simpler to use:
>
> -record(state, { timeout = 1000 }).
>
> my_state(Data, #state{timeout = Timeout} = State) ->
> handle_protocol(Data),
> {next_state, my_state, State, Timeout};
> my_state(timeout, #state{timeout = Timeout} = State) ->
> keepalive(),
> {next_state, my_state, State, Timeout}.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list