接收缓冲区的限制 [英] limitation of the reception buffer

查看:243
本文介绍了接收缓冲区的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  gen_tcp:listen(1234,[binary,{packet,0 },{reuseaddr,TRUE},{活性,FALSE},{recbuf,2048}])。 

此代码执行消息处理:

 环(插座) - > 
inet:setops(Socket,[{active,once}],
receive
{tcp,Socket,Data} - >
句柄(数据),
loop(Socket);
{Pid,Cmd} - >
gen_tcp:send(Socket,Cmd),
loop(Socket);
{tcp_close,Socket} - > ;
%...
end。

我的操作系统是Windows消息的大小是1024字节,我在数据中丢失字节,服务器向客户端发送ACK + FIN。



我相信Erlang被限制在1024字节,因此我定义了 recbuf



是:Erlang,Windows,硬件?



谢谢。

解决方案

您可能设置的接收缓冲区太小,Erlang当然不限于1024字节缓冲区,您可以通过在shell中执行以下操作来检查自己:

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

在Mac OS XI上,获取约512Kb的默认接收缓冲区大小。






使用 {packet,0} 解析,您将以任何块的形式收到tcp数据选择发送它,所以你必须做消息边界解析和缓冲。你有一种可靠的方法来检查线路协议中的消息边界吗?如果是这样,请接收tcp数据并将其附加到缓冲区变量,直到有完整的消息。然后在完成邮件后调用句柄,然后在继续之前从缓冲区中删除完整的邮件。



如果您向客户提供了一些信息,协议正在使用中。


I established a connection with a client this way:

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 size of the message is 1024 bytes, I lose bytes in Data. The server sends ACK + FIN to the client.

I believe that the Erlang is limited to 1024 bytes, therefore I defined recbuf.

Where the problem is: Erlang, Windows, hardware?

Thanks.

解决方案

You may be setting the receive buffer far too small. Erlang certainly isn't limited to a 1024 byte buffer. You can check for yourself by doing the following 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 about 512Kb.


With {packet, 0} parsing, you'll receive tcp data in whatever chunks the network stack chooses to send it in, so you have to do message boundary parsing and buffering yourself. Do you have a reliable way to check message boundaries in the wire protocol? If so, receive the tcp data and append it to a buffer variable until you have a complete message. Then call handle on the complete message and remove the complete message from the buffer before continuing.

We could probably help you more if you gave us some information on the client and the protocol in use.

这篇关于接收缓冲区的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆