anchor.diff:  %% %CopyrightEnd%
   %%
   
  -%%% Generic connection owner process.
  -%%%
  -%%% -type handle() = pid(). A handle for using a connection implemented
  -%%% with ct_gen_conn.erl.
  +%%
  +%% Generic connection owner process.
  +%%
   
   -module(ct_gen_conn).
   
  --export([start/4, stop/1, get_conn_pid/1, check_opts/1]).
  --export([call/2, call/3, return/2, do_within_time/2]).
  --export([log/3, start_log/1, cont_log/2, cont_log_no_timestamp/2, end_log/0]).
  +-behaviour(gen_server).
  +
  +-export([start/4,
  +         stop/1,
  +         get_conn_pid/1]).
  +
  +-export([call/2,
  +         call/3,
  +         return/2,
  +         do_within_time/2]).
  +
  +-export([log/3,
  +         start_log/1,
  +         cont_log/2,
  +         cont_log_no_timestamp/2,
  +         end_log/0]).
  +
  +%% gen_server callbacks
  +-export([init/1,
  +         handle_info/2,
  +         handle_cast/2,
  +         handle_call/3,
  +         code_change/3,
  +         terminate/2]).
  +
  +%% test
  +-export([make_opts/1]).
   
   -ifdef(debug).
   -define(dbg,true).
  
positive.code: -define(dbg,false).
  -endif.
  
  -record(gen_opts,{callback,
  		  name,
  		  address,
  		  init_data,
  		  reconnect    = true,
  		  forward      = false,
  		  use_existing = true,
  		  old          = false,
  		  conn_pid,
  		  cb_state,
  		  ct_util_server}).
  
  %%%-----------------------------------------------------------------
  %%% -spec start(Address,InitData,CallbackMod,Opts) ->
  %%%                                     {ok,Handle} | {error,Reason}
  %%%      Name = term()
  %%%      CallbackMod = atom()
  %%%      InitData = term()
  %%%      Address = term()
  %%%      Opts = [Opt]
  %%%      Opt = {name,Name} | {use_existing_connection,boolean()} |
  %%%            {reconnect,boolean()} | {forward_messages,boolean()}
  %%%
  %%% Open a connection and start the generic connection owner process.
  %%%
  %%% The CallbackMod is a specific callback module for
  %%% each type of connection (e.g. telnet, ftp,...). It must export the
  %%% function init/3 which takes the arguments
  %%% Name, Addresse) and
  %%% InitData and returna
  %%% {ok,ConnectionPid,State} or
  %%% {error,Reason}.
  %%%
  %%% If no name is given, the Name argument in init/3 will
  %%% have the value undefined.
  %%%
  %%% The callback modules must also export
  %%%
  %%% handle_msg(Msg,From,State) -> {reply,Reply,State} |
  %%%                               {noreply,State} |
  %%%                               {stop,Reply,State}
  %%% terminate(ConnectionPid,State) -> term()
  %%% close(Handle) -> term()
  %%%
  %%% The close/1 callback function is actually a callback
  %%% for ct_util, for closing registered connections when
  %%% ct_util_server is terminated. Handle is the Pid of
  %%% the ct_gen_conn process.
  %%%
  %%% If option reconnect is true, then the
  %%% callback must also export
  %%%
  %%% reconnect(Address,State) -> {ok,ConnectionPid,State}
  %%%
  %%% If option forward_messages is <ocde>true, then
  %%% the callback must also export
  %%%
  %%% handle_msg(Msg,State) -> {noreply,State} | {stop,State}
  %%%
  %%% An old interface still exists. This is used by ct_telnet, ct_ftp
  %%% and ct_ssh. The start function then has an explicit
  %%% Name argument, and no Opts argument. The
  %%% callback must export:
  %%%
  %%% init(Name,Address,InitData) -> {ok,ConnectionPid,State}
  %%% handle_msg(Msg,State) -> {Reply,State}
  %%% reconnect(Address,State) -> {ok,ConnectionPid,State}
  %%% terminate(ConnectionPid,State) -> term()
  %%% close(Handle) -> term()
  %%%
  start(Address,InitData,CallbackMod,Opts) when is_list(Opts) ->
      do_start(Address,InitData,CallbackMod,Opts);
  start(Name,Address,InitData,CallbackMod) ->
      do_start(Address,InitData,CallbackMod,[{name,Name},{old,true}]).
  
  %%%-----------------------------------------------------------------
  %%% -spec stop(Handle) -> ok
  %%%      Handle = handle()
  %%%
  %%% Close the connection and stop the process managing it.
  stop(Handle) ->
      call(Handle,stop,5000).
  
  %%%-----------------------------------------------------------------
  %%% -spec get_conn_pid(Handle) -> ok
  %%%      Handle = handle()
  %%%
  %%% Return the connection pid associated with Handle
  get_conn_pid(Handle) ->
      call(Handle,get_conn_pid).
  
  %%%-----------------------------------------------------------------
  %%% -spec log(Heading,Format,Args) -> ok
  %%%
  %%% Log activities on the current connection (tool-internal use only).
  %%% See ct_logs:log/3
  log(Heading,Format,Args) ->
      log(log,[Heading,Format,Args]).
  
  %%%-----------------------------------------------------------------
  %%% -spec start_log(Heading) -> ok
  %%%
  %%% Log activities on the current connection (tool-internal use only).
  %%% See ct_logs:start_log/1
  start_log(Heading) ->
      log(start_log,[Heading]).
  
  %%%-----------------------------------------------------------------
  %%% -spec cont_log(Format,Args) -> ok
  %%%
  %%% Log activities on the current connection (tool-internal use only).
  %%% See ct_logs:cont_log/2
  cont_log(Format,Args) ->
      log(cont_log,[Format,Args]).
  
  %%%-----------------------------------------------------------------
  %%% -spec cont_log_no_timestamp(Format,Args) -> ok
  %%%
  %%% Log activities on the current connection (tool-internal use only).
  %%% See ct_logs:cont_log/2
  cont_log_no_timestamp(Format,Args) ->
      log(cont_log_no_timestamp,[Format,Args]).
  
  %%%-----------------------------------------------------------------
  %%% -spec end_log() -> ok
  %%%
  %%% Log activities on the current connection (tool-internal use only).
  %%% See ct_logs:end_log/0
  end_log() ->
      log(end_log,[]).
  
  %%%-----------------------------------------------------------------
  %%% -spec do_within_time(Fun,Timeout) -> FunResult | {error,Reason}
  %%%      Fun = function()
  %%%      Timeout = integer()
  %%%
  %%% Execute a function within a limited time (tool-internal use only).
  %%%
  %%% Execute the given Fun, but interrupt if it takes
  %%% more than Timeout milliseconds.
  %%%
  %%% The execution is also interrupted if the connection is
  %%% closed.
  do_within_time(Fun,Timeout) ->
      Self = self(),
      Silent = get(silent),
  
negative.code: %%
  %% %CopyrightBegin%
  %%
  %% Copyright Ericsson AB 2003-2021. All Rights Reserved.
  %%
  %% Licensed under the Apache License, Version 2.0 (the "License");
  %% you may not use this file except in compliance with the License.
  