Reputation: 98
in an Erlang process, how could i receive from an ssl socket, and at the same time receive from another erlang process with the receive primitive?
the idea is to forward what comes from the socket to another process; and backwards.
my only option so far is to use some time receiving from each end, then switch. that, of course, will delay the processing of the messages received on one interface, while receiving from the other one. do you see any other way to do this? if only Erlang would let me use one process to receive from the socket, and another one to send to the socket...
Upvotes: 1
Views: 502
Reputation: 57648
Not sure I understand your question; anyway, you can have multiple "clauses" in a receive statement, so it becomes "unblocked" when receiving something from either side:
loop() ->
receive
{ssl, Msg} -> % incoming msg from SSL, send it to process
Proc ! Msg,
loop();
{proc, Msg} -> % incoming msg from process, send it to SSL
SSL ! Msg,
loop()
end.
The important thing is that you need to format your messages in a way that you can differentiate between SSL and process messages with pattern matching.
Upvotes: 3