Erlang TCP 服务器 - 混合套接字模型

Erlang TCP Server - Hybrid Socket Model

我正在尝试在 Erlang 中实现混合 (active/passive) 套接字模型 TCP 服务器:

%%%-------------------------------------------------------------------
%%% @author mylesmcdonnell
%%% @copyright (C) 2015, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 04. Feb 2015 14:01
%%%-------------------------------------------------------------------
-module(mmkvstore_srv).
-author("mylesmcdonnell").

%% API
-export([start/1]).

start(Port) ->
  {ok, Listen} = gen_tcp:listen(Port, [binary, {packet, 4}, {reuseaddr, true}, {active, once} ]),
  spawn(fun() -> connect(Listen) end).

connect(Listen) ->
  io:format("Waiting for connection~n"),
  {ok, Socket} = gen_tcp:accept(Listen),
  io:format("Connection accepted~n"),
  spawn(fun() -> connect(Listen) end),
  loop(Socket).

loop(Socket) ->
  receive
    {tcp, Socket, Bin} ->
      io:format("Server msg rcvd~n"),
      gen_tcp:send(Socket, Bin),
      inet:setops(Socket, [{active, once}]),
      loop(Socket);
    {tcp_closed, Socket} ->
      io:format("Socket closed~n");
    _ ->
      io:format("Unmatched message rcvd ~n")
  end.

但是,将套接字重置为活动状态的调用 (inet:setops(Socket, [{active, once}]),) 失败并显示以下内容:

=ERROR REPORT==== 4-Feb-2015::16:25:24 ===
Error in process <0.156.0> with exit value: {undef,[{inet,setops,[#Port<0.2581>,[{active,once}]],[]},{mmkvstore_srv,loop,1,[{file,"mmkvstore_srv.erl"},{line,34}]}]}

我正在关注 Programming Erlang 2.0 Chp17。问题是否与在同一套接字上发送的前一行有关?

inet:setopts/2,不是inet:setops/2undef表示没有这个功能,或者说没有导出。