! This will test RMIF when a remote client finishes opening connection to
! the RMIF server (e.g. it is in an OPENED state) and then gets killed
! before the remote client sends it's next PING packet (default is a 5 second
! window).
!
! This causes the RMIF server to think that the client is still OPENED and will
! continue sending data (e.g. ACK, GET, SET, etc.) to that remote client when
! the upper level (macro) requests it.
!
! Test Scenario
!     Start Server
!     Start Client
!     Kill Client after getting ACK (before client sends next PING)
!     Server connection to remote Client should timeout after ~16 sec (default)
!
! @author  Neon Ngo
! @bug     2017 OPENED remote clients do not timeout sometimes
! @requires NeXtMidas 2.7.3 (for killing RMIF client instance)
!
startmacro L:sPort[-1] D:timeout[40]
  switch DEBUG         debug        GET DEF=false    SDEF=true
  switch DEBUGSERVER   debugs       GET DEF=^debug   SDEF=true
  switch DEBUGCLIENT   debugc       GET DEF=^debug   SDEF=true
  switch VERBOSE       verbose      GET DEF=false    SDEF=true
  switch VERBOSESERVER verboses     GET DEF=^verbose SDEF=true
  switch VERBOSECLIENT verbosec     GET DEF=^verbose SDEF=true
  switch STATEM        statemachine GET DEF=false    SDEF=true

  timer set

  invoke vercomp nxm.sys.lib.StringUtil.compareVersions("^env.nmversion","2.7.3")
  if vercomp LT 0 then
    info "^reg.main.name: requires NeXtMidas 2.7.3+..........SKIP"
    stop
  endif

  call standardSetup timeout sPort
  pipe on
    %test_rmif_remote_timeout_server/id=SERVER/STATEM=^statemachine/DEBUG=^debugs/VERBOSE=^verboses/BG this ^sPort
    %test_rmif_remote_timeout_client/id=CLIENT/STATEM=^statemachine/DEBUG=^debugc/VERBOSE=^verbosec/BG this ^sPort
  pipe off

  timer elapse
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 false then ! Your message name goes here
    !
    ! Your message(s) processing goes here
    !
  else
    call processStandardMessages
  endif
return

! These are a set of standard procedures
include standard_rmif_procs.mminc
