Erlang: Avoiding race condition with gen_tcp:controlling_process

后端 未结 3 925
抹茶落季
抹茶落季 2021-02-05 23:42

I am implementing simple tcp server with the following sequence:

{ok, LS} = gen_tcp:listen(Port,[{active, true}, {reuseaddr, true}, {mode, list}]),
{ok, Socket}          


        
3条回答
  •  别跟我提以往
    2021-02-06 00:15

    If the socket is active, inet:tcp_controlling_process (called by gen_tcp:controlling_process) sets the socket to passive, then selectively receives all messages related to that socket and sends them to the new owner, effectively moving them to the new owner's message queue. Then it restores the socket to active.

    So there's no race condition: they have already thought of that and fixed it in the library.

提交回复
热议问题