[erlang-questions] gen_tcp:controlling_process/2 impact

Fred Hebert mononcqc@REDACTED
Tue Aug 18 15:12:24 CEST 2015


On 08/18, Benoit Chesneau wrote:
>Hi all,
>
>I am working on some some code that may need to chain and passe a socket
>connection between multiple process in a rapid manner and I am wondering
>what is the real impact of chaining multiple  `gen_tcp:controlling_process`
>from one process to the other in a very fast manner.  Is there any
>possibility to bypass it and just give the control to the target at the end?
>

If the socket is used only for writing, then you don't need to change 
the controlling process, just send the thing directly. Anyone can write 
to a socket, just one process can read.

If you do need to read from it, then the best idea is likely to resolve 
your chain, find the final destination pid, and hand the control there.  
The owner must hand the control, so rather than going:

a -- give --> b -- give --> c

go

a -- ask pid --> b -- finds --> c
a -- give --> c

which will have a single control-handing form. You can also swap it 
around and let 'b' tell 'c' to "ask a for your port" and then do the 
switch.

Also remember to let the socket in {accept, false} mode so that no 
messages are lost during the whole operation.



More information about the erlang-questions mailing list