[erlang-questions] Erlang get_tcp:recv data length

Andrew Thompson <>
Wed Feb 23 20:29:37 CET 2011

On Wed, Feb 23, 2011 at 03:46:38PM +0000, Alexander Kuleshov wrote:
> >Alexander didn't say how many packets he could receive, the separator
> I don't know how many packets i must receive. I receive smtp must data message
> Data
> bla bla bla
> .
> Separator  dot - .\r\n
Actually, you need to check for \r\n.\r\n, just .\r\n by itself isn't
guranteed to be the end of data.

I receive the message body in gen_smtp by spawning a new process and
looping doing a recv until the buffer contains "\r\n.\r\n", then I
return the resulting binary and any trailing data back to the original
process. I do it in a subprocess to help the garbage collector be able
to clean all the mess up when the subprocess exits.


The recv size adjustment is kinda ugly, but it seems to work pretty

Also, you can use the SMTP SIZE extension to get a vague idea of how
much data you're going to get. Just don't trust it, its only a


More information about the erlang-questions mailing list