Receive Buffer Limit

I established a connection with the client as follows:

gen_tcp:listen(1234,[binary,{packet,0},{reuseaddr,true},{active,false},{recbuf,2048}]).

This code performs message processing:

loop(Socket)->
    inet:setops(Socket,[{active,once}],
    receive
        {tcp,Socket,Data}->
            handle(Data),
            loop(Socket);
        {Pid,Cmd}->
            gen_tcp:send(Socket,Cmd),
            loop(Socket);
        {tcp_close,Socket}->
            % ...
end.

My OS is Windows. When the message size is 1024 bytes, I lose bytes in Data. The server sends ACK + FIN to the client.

I believe Erlang is limited to 1024 bytes, so I defined recbuf.

Where is the problem: Erlang, Windows hardware?

Thank.

+3
source share
1 answer

You may be setting the receive buffer too much. Erlang, of course, is not limited to a 1024-byte buffer. You can verify it yourself by following these steps in the shell:

{ok, S} = gen_tcp:connect("www.google.com", 80, [{active,false}]),
O = inet:getopts(S, [recbuf]),
gen_tcp:close(S),
O.

On Mac OS X, I get a default receive buffer size of around 512KB.


{packet, 0} tcp , , . ? , tcp , . , .

, .

+2

Source: https://habr.com/ru/post/1787764/


All Articles