[erlang-questions] gen_tcp and processes receiving

Bruce Fitzsimons Bruce@REDACTED
Fri Oct 5 04:53:47 CEST 2007


Stephan Maka wrote:
> Hi
>
>
> I'm unsure about the use of gen_tcp:controlling_process when I simply
> use a passive socket. Active sockets are no option here, I have strong
> traffic shaping requirements.
>   
Your code starts working when you change the recv length to 0 (e.g. 
unspecified) and stop expecting only one list elemet e.g. B instead of 
[B]. Your use of controlling_process is completely appropriate (think of 
it as moving the socket spout from one process to another, in active 
mode it would start spewing data at the new process.)

The documentation isn't crystal clear on this point as it says: "The 
|Length| argument is only meaningful when the socket is in |raw| mode 
and denotes the number of bytes to read." rather than something like 
"The |Length| argument should only be non-zero when the socket is in 
|raw| mode and then it denotes the number of bytes to read.".

Your socket is not in raw mode so you'll need to manage excess bytes 
yourself by buffering in a process if you want to process in 
protocol-defined-chunks. I've not used raw mode but it may be appropriate.

Cheers,
Bruce



More information about the erlang-questions mailing list