[erlang-questions] "calling" a gen_fsm

Garry Hodgson garry@REDACTED
Tue Sep 22 16:03:21 CEST 2015

i'm using a gen_fsm to implement the client side of
a binary protocol. clients connect to a controller, do
a login thing, then settle into connected state. so far,
so good.

when in connected state, i need to be able to query
the fsm for information. some of these queries require
sending a message to a controller and waiting for a
response to come back. herein lies the problem, because
the query relies on the sync event to ask the question,
but must wait for an { ssl, Socket, Data } event to get
the answer.

i've got it sort of working, but only by intercepting the
ssl message inline, vs. the normal handle_info() method.
this feels like cheating, and seems fragile, as it relies on
there being no intervening messages.

so i'm wondering, is there a good/standard way of
accomplishing this? or is gen_fsm not the right approach?
any advice would be appreciated.


code snippets follow:

who_provides( Service ) -> gen_fsm:sync_send_event( ?MODULE, { 
request_services, Service } ).
connected( { request_services, Service }, _From, #state{ socket=Socket, 
transport=Transport } = State ) ->
     Transport:send( Socket, service_request( Service ) ),
     case wait_for_services( Socket ) of
         { ok, Services } ->
             { reply, { ok, Services }, connected, State };
         Other ->
             { reply, { error, Other }, connected, State }

wait_for_services( Socket ) ->
         { ssl, Socket, Data } ->
             ssl:setopts( Socket, [ { active, once } ] ),
             { ok, parse( Data ) }
     after 30000 ->

Garry Hodgson
Lead Member of Technical Staff
AT&T Chief Security Office (CSO)

"This e-mail and any files transmitted with it are AT&T property, are confidential, and are intended solely for the use of the individual or entity to whom this e-mail is addressed. If you are not one of the named recipient(s) or otherwise have reason to believe that you have received this message in error, please notify the sender and delete this message immediately from your computer. Any other use, retention, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited."

More information about the erlang-questions mailing list