Recieve packet from socket in Erlang active mode with ASCII packet size header
Jesper Louis Andersen
jesper.louis.andersen@REDACTED
Mon Jan 4 17:57:58 CET 2021
On Mon, Jan 4, 2021 at 3:40 PM George Hope <george@REDACTED> wrote:
> By synchronous I mean if the program does not finish processing processing
> of first packet and packet 2,3 arrived does Erlang VM wait for handle_info
> to return?
> Is it possible to lose sequnce of packets?
>
Yes, it will wait. Packets that arrive are placed in the process mailbox.
The gen_server main event loop will look into the mailbox and if it isn't
one of the "specially tagged" messages that invokes a handle_cast or
handle_call, it is passed to handle_info for processing, one at a time. You
are guaranteed that other messages will arrive in the mailbox, subject to
the Erlang message ordering guarantees.
> As far as I know handle_call is sync and handle_cast is async in
> gen_server.
>
>
Ah! In this case, this pertains to a client's view if it calls a gen_server.
When you cast to a server, you send a message into the mailbox, and you
don't wait as a client. The server will eventually get to the message in
the mailbox and process it through handle_cast.
When you call a server, your client blocks until it receives a reply or
times out. The server will eventually get to the message in the mailbox and
process it through handle_call. If handle_call replies, the client is
unblocked.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210104/7261f182/attachment.htm>
More information about the erlang-questions
mailing list