[erlang-questions] gen_tcp, {packet, http}, and recieve buffer size

Matthew Reilly <>
Fri Sep 29 02:59:06 CEST 2006


Eric Merritt wrote:
> Guys,
>
>   I have a question about one of the undocumented features of gen_tcp.
> When using the http packet type in gen_tcp, parsing fails if data
> associated with the http get request is larger then the receive
> buffer. At least, after a bit of testing this looks like the problem
> we are seeing. Of course, this is just a prototype and not a
> production system so its no big deal, but it did kick in my curiosity.
> So is this a bug?
>
> Thanks,
>  Eric
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>   

You can set the recbuf option when creating the TCP port to more than 
1024 by including e.g. {recbuf, 8192} in the gen_tcp:connect options. 
This allows lines of up to 8K in the HTTP Headers. The problem you've 
seen not only affects the Request URI, but any long line in the HTTP 
header. (e.g. I've hit this limit with large cookies).

Note: This doesn't work for SSL (since the ssl module dis-allows 
'recbuf'). If you think this may be a problem, here is one fix:

In the Erlang/OTP source directory, edit the file: 
./erts/emulator/drivers/common/inet_drv.c
Change
   #define INET_DEF_BUFFER     1024        /* default buffer size */
To:
   #define INET_DEF_BUFFER     (1024*8)        /* default buffer size */

Then recompile Erlang/OTP and re-install.

Matt Reilly
SIPphone Inc.



More information about the erlang-questions mailing list