Access to a socket from two processes

Is it allowed to read one process and another process of writing to a socket in Erlang? I tried this and it seems to work, but I would like to know if it is safe.

+3
source share
3 answers

As I understand from the source code, (socket_tcp, at least) socket send / recv comes down to erlang: port_command for send and erlang: port_control for recv on the socket port (see prim_inet.erl).

For port_command: "if the port is busy, the call process will be suspended until the port is busy." Port_control is also a synchronous operation.

Correct me if I am wrong, but it would be completely safe to use several processes to read and write to the socket.

+3

, , .

+1

Any of them can write, but that would not make sense if all your processes could receive. This would flood the mailboxes of all those who did not expect messages. You need to define only one Pid for receiving packets, by default this is regardless of which Pid was created on the socket. You can set any Pid for socket control by setting the control process.

+1
source

Source: https://habr.com/ru/post/1763192/


All Articles