[erlang-questions] Why netconf_client:get_result Timeout value is not used in its xmerl contiuation_fun?

Tien Le <>
Mon Oct 28 18:37:57 CET 2013


Hi,

In the netconf_client.erl code, The user-defined "Timeout" is passed down
until it is used in "receive ... after Timeout" expression in
netconf_transport:receive_data/2

However during the XML processing step, the continuation_fun called cont/3
uses netconf_transport:receive_data/1 once again, but with "receive ...
after infinity"

Does it mean that the Timeout which user has entered is not used in the
continuation_fun? What happens if the netconf_transport:receive_data/1
takes longer than the "Timeout"?

Here is the code snippet:

%%%%%%%%%%%%% netconf_client.erl %%%%%%%%%%%%%

get_result(Connection, Timeout) ->
    case *netconf_transport:receive_data(Connection, Timeout)* of
    {ok, Data} ->
        case to_simple_xml(Data, Connection) of
        {'rpc-reply',_Attrs,Result} ->
            Result;
        {'nc:rpc-reply',_Attrs,Result} ->
            Result;
        OtherReply ->
            OtherReply
        end;
    {error, Reason} ->
        {error, Reason}
    end.

to_simple_xml(Bin, Connection) when is_binary(Bin) ->
    {SimpleXml,_Rest} = xmerl_scan:string("",
                    [{*continuation_fun, fun cont/3,*
                      {Bin, false, Connection}},
                     {acc_fun,fun acc_simple_xml/3},
                     {space,normalize},
                     {hook_fun, fun hook_simple_xml/2}]),
    SimpleXml.

cont(Continue, Exception, GlobalState) ->
    {OldTail, Found, Connection} = xmerl_scan:cont_state(GlobalState),
    if
    Found ->
        Continue(Exception,GlobalState);
    true ->
        case split_at_marker_or_last_whitespace(OldTail) of
        false ->
            *%% Need more data.
            {ok, Data} = netconf_transport:receive_data(Connection),*
            NewGlobalState =
            xmerl_scan:cont_state(
              {<<OldTail/binary,Data/binary>>, false, Connection},
              GlobalState),
            cont(Continue, Exception, NewGlobalState);
        {Marker, NewData, NewTail} ->
            NewGlobalState =
            xmerl_scan:cont_state({NewTail, Marker, Connection},
                          GlobalState),
            netconf_transport:adjust_window(Connection, length(NewData) +
                            case Marker of
                            true ->
                                6;
                            _ ->
                                0
                            end),
            Continue(NewData, NewGlobalState)
        end
    end.

%%%%%%%%%%%%% netconf_transport.erl %%%%%%%%%%%%%
receive_data(Connection) ->
    receive_data(Connection, *infinity*).
receive_data(#connection{transport = ssh}, Timeout) ->
    receive
    {ssh_cm, _Cm, {data, _Ch, _Type, Data}} ->
        {ok, Data};
        {ssh_cm, _Cm, {Closed, _Ch}} when Closed == closed; Closed == eof ->
            exit(closed);
        {'DOWN',_,_,_,_} ->
            exit(normal)
    after *Timeout* ->
        {error, timeout}
    end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20131028/bbd0485a/attachment.html>


More information about the erlang-questions mailing list