<div dir="ltr"><div>Just use {next_state,NextStateName,NewStateData} instead of {reply,Reply,NextStateName,NewStateData} and keep the PID of the calling process in the NewStateData. This helps you in deferring the response. When the data comes form the service, you can send the response back with gen_fsm:reply(PID, Reply).</div><div><br></div><div>Theepan</div><div> </div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 22, 2015 at 7:33 PM, Garry Hodgson <span dir="ltr"><<a href="mailto:garry@research.att.com" target="_blank">garry@research.att.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">i'm using a gen_fsm to implement the client side of<br>
a binary protocol. clients connect to a controller, do<br>
a login thing, then settle into connected state. so far,<br>
so good.<br>
<br>
when in connected state, i need to be able to query<br>
the fsm for information. some of these queries require<br>
sending a message to a controller and waiting for a<br>
response to come back. herein lies the problem, because<br>
the query relies on the sync event to ask the question,<br>
but must wait for an { ssl, Socket, Data } event to get<br>
the answer.<br>
<br>
i've got it sort of working, but only by intercepting the<br>
ssl message inline, vs. the normal handle_info() method.<br>
this feels like cheating, and seems fragile, as it relies on<br>
there being no intervening messages.<br>
<br>
so i'm wondering, is there a good/standard way of<br>
accomplishing this? or is gen_fsm not the right approach?<br>
any advice would be appreciated.<br>
<br>
thanks<br>
<br>
code snippets follow:<br>
<br>
who_provides( Service ) -> gen_fsm:sync_send_event( ?MODULE, { request_services, Service } ).<br>
...<br>
connected( { request_services, Service }, _From, #state{ socket=Socket, transport=Transport } = State ) -><br>
    Transport:send( Socket, service_request( Service ) ),<br>
    case wait_for_services( Socket ) of<br>
        { ok, Services } -><br>
            { reply, { ok, Services }, connected, State };<br>
        Other -><br>
            { reply, { error, Other }, connected, State }<br>
    end.<br>
<br>
wait_for_services( Socket ) -><br>
    receive<br>
        { ssl, Socket, Data } -><br>
            ssl:setopts( Socket, [ { active, once } ] ),<br>
            { ok, parse( Data ) }<br>
    after 30000 -><br>
        timeout<br>
    end.<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
-- <br>
Garry Hodgson<br>
Lead Member of Technical Staff<br>
AT&T Chief Security Office (CSO)<br>
<br>
"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."<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</font></span></blockquote></div><br></div>