[erlang-questions] How does Erlang TCP determine the end of a TCP stream?

Сергей Прохоров seriy.pr@REDACTED
Wed Nov 1 16:15:19 CET 2017


You may look at epgsql's packet parser as an example. It has packet-type +
packet-length - prefixed packet structure and it doesn't use {packet, N}
option.

handle_info({_, Sock, Data2}, ...)
https://github.com/epgsql/epgsql/blob/3.2.0/src/epgsql_sock.erl#L152

tail buffering
https://github.com/epgsql/epgsql/blob/3.2.0/src/epgsql_sock.erl#L359

here we check packet bounds
https://github.com/epgsql/epgsql/blob/3.2.0/src/epgsql_wire.erl#L22


> Stanislaw,
> Is there a common solution to this problem? Erlang was built to be used in
> servers/switches, i would assume that there was a solution built into OTP?
> If not, do you handle it just at the application later with gen_tcp:recv()
> and read X bytes at a time from the socket based on delimiters and such?
> How would you reconcile this with using a gen_server implementation that
> receives messages from the ssl socket in handle info ?
> I appreciate the help, I?m happy I didn?t roll this further
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171101/405697ab/attachment.htm>


More information about the erlang-questions mailing list