<div dir="ltr"><div><div><div><div><div><div>First Chapter 3:<br></div>TCP requests aren't passed to handle_call or handle_cast by gen_tcp, they're passed by the tr_server:do_rcp function.<br>When gen_tcp:listen is called it's passed {active, true} as an option. This tells gen_tcp to send events as messages to the process that started it, in this case the tr_server process.<br>
</div>Any messages sent to a gen_server not using gen_cast or gen_call arrive in the handle_info functions which is why you see the handle_info({tcp, Socket, RawData}, State) function. It is that function that calls do_rpc which in turn calls gen_cast and gets your data to your handle_cast functions.<br>
</div><div>I suggest reading <a href="http://erlang.org/doc/man/gen_tcp.html">http://erlang.org/doc/man/gen_tcp.html</a>, it explains this quite well.<br></div><br>Chapter 6:<br></div>the returns from your callback functions (the ones that look like {noreply, State, Timeout}) return the timeout. Once the gen_server process reaches that timeout the timeout callback is fired which stops the process. Process holding data for that key stops =:= key expired, no explicit expiry is necessary which is why you don't see code for it.<br>
</div>Again, give <a href="http://www.erlang.org/doc/man/gen_server.html">http://www.erlang.org/doc/man/gen_server.html</a> a good read, it's all explained in there.<br><br></div></div><div class="gmail_extra"><br><br>
<div class="gmail_quote">On Tue, Jun 10, 2014 at 12:41 AM, Ben Hsu <span dir="ltr"><<a href="mailto:benhsu@gmail.com" target="_blank">benhsu@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hello!<div><br></div><div>I am reading the Manning OTP book ( <a href="http://www.manning.com/logan/" target="_blank">http://www.manning.com/logan/</a> , <a href="https://github.com/erlware/Erlang-and-OTP-in-Action-Source" target="_blank">https://github.com/erlware/Erlang-and-OTP-in-Action-Source</a> ), and I have three questions:</div>
<div><br></div><div>In chapter 3, which is about the RPC server, I'm not sure how OTP hooks up with gen_tcp. I see that tr_server.erl calls gen_tcp:listen, but I don't see how TCP requests are passed to handle_call or handle_cast. I'm also not clear on how TCP requests are transformed into Erlang function arguments.</div>
<div><br></div><div>In chapter 6, which is about making a network cache, I'm not sure how the timeout works. I see that sc_element:handle_call gets the Starttime and Leasetime from the State variable, and computes a time left. I'm not sure how the time left variable is used to expire the cache. I thought there will be a line of code where we check if Timeleft < 0, but I can't find any such line. Is this handled inside OTP?</div>
<div><br></div><div>Thank you. I am very excited to be learning OTP</div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><div dir="ltr"><div>Thomas van Neerijnen<br></div><a href="http://tomvn.com" target="_blank">http://tomvn.com</a><br><div>+4477 1709 7670</div></div>
</div>