!
! Client (sender) side of test case to verify status of RMIF link when the Server (Remote)
! side of the link is arbitrarily killed and brought back up on the same port.
! Test case does not fit into our RMIF test framework yet. The Server side has to
! be killed and restarted manually. Working on automating it.
! Discrepency noted by Jeremy N.
!
! Scenario we are trying to emulate
!     Start Server
!     Start Client
!     Kill Server
!     Start Server
!
! <cntrl>   - The parent control macro object
! <port>    - The KNOWN port of the server.  Client uses any available port.
!
! @bug     1541
! @author  Jim Roush
! @since   NeXtMidas 2.7.0
!
startmacro O:cntrl L:port[9013] S:host["LOCALHOST"] L:timeout[60] L:cPort[-1]
  switch TRACE   trace        GET DEF=false SDEF=true
  switch DEBUG   debug        GET DEF=false SDEF=true
  switch VERBOSE verbose      GET DEF=false SDEF=true
  switch STATEM  statemachine GET DEF=false SDEF=true

  set reg.cntrl  cntrl  ! save reference to parent control macro
!  set L:anyAvailablePort -1

  pipe on
    ! startup client (sender) RMIF
    say "Connecting to: ^host:^port"
    rmif/id=SENDER/msgid=MAIN/STATEM=^statemachine/VERBOSE=^verbose ^cPort
    message FUNC=sendw ID=SENDER NAME="OPEN" DATA={ID="REMOTE",HP="^host:^port"}

    invoke ,, SENDER.rmif.setverbose(debug)    ! "invoke"s were provided by
    invoke ,, SENDER.rmif.setDebug(debug)      ! Jeremy to emulate his operating
!    invoke ,, SENDER.rmif.setMaxQueue(5120)   ! conditions. Most of them had no
!    invoke ,, SENDER.rmif.setWindow(50)       ! bearing on the issues that
!    invoke ,, SENDER.rmif.setRetry(100)       ! caused the problem. They are
                                               ! included here for completeness.
    invoke ,, SENDER.rmif.setTimeOut(timeout)  ! This setting impacts test case, original setting 120.
  pipe off
endmacro

!******************************************************************************!
procedure processMessage m:msg
  if debug then
    say "^reg.main.name: Got message name=^msg.name fid=^msg.fid info=^msg.info data=^msg.data"
  endif

  if msg.name eqs "OPENED" then
    message FUNC=SEND ID=REMOTE NAME="ADDC" INFO=0 DATA="Q:ACK"
  elseif msg.name eqs "NULL" then
    ! ignore
  elseif msg.name eqs "LINKERR" then
    say "********************************************************"
    say "Got message name=^msg.name from=^msg.from info=^msg.info data=^msg.data"
    say "********************************************************"
  else
    say "Got message name=^msg.name from=^msg.from info=^msg.info data=^msg.data"
  endif
return
