Re: Recieve packet from socket in Erlang active mode with ASCII packet size header

Jesper Louis Andersen <[email protected]>
Newsgroups gmane.comp.lang.erlang.general
Message-ID <CAGrdgiUK_UAvaWMcS2yecs47CuoCe2oz=GfOodVWNzrZj=cwLA@mail.gmail.com>
On Mon, Jan 4, 2021 at 3:40 PM George Hope <[email protected]> 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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.