[erlang-questions] Manning OTP questions

Tom van Neerijnen tom@REDACTED
Tue Jun 10 10:06:25 CEST 2014


First Chapter 3:
TCP requests aren't passed to handle_call or handle_cast by gen_tcp,
they're passed by the tr_server:do_rcp function.
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.
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.
I suggest reading http://erlang.org/doc/man/gen_tcp.html, it explains this
quite well.

Chapter 6:
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.
Again, give http://www.erlang.org/doc/man/gen_server.html a good read, it's
all explained in there.



On Tue, Jun 10, 2014 at 12:41 AM, Ben Hsu <benhsu@REDACTED> wrote:

> Hello!
>
> I am reading the Manning OTP book ( http://www.manning.com/logan/ ,
> https://github.com/erlware/Erlang-and-OTP-in-Action-Source ), and I have
> three questions:
>
> 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.
>
> 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?
>
> Thank you. I am very excited to be learning OTP
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>


-- 
Thomas van Neerijnen
http://tomvn.com
+4477 1709 7670
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140610/11906877/attachment.htm>


More information about the erlang-questions mailing list