INHVTMT5 ; KAC ; 06 Aug 1999 15:34:58; Multi-threaded TCP/IP socket utilities
;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
;COPYRIGHT 1991-2000 SAIC
Q
;
HB(INHBSENT,INHBWAIT) ; Function:
; Heartbeat/dummy msg sent to indicate when transceiver can start
; sending msgs from UNIVERSAL INTERFACE file. Adds SOM and EOM
; to start/end of msg.
;
; Called by: INHVTMT
;
;Input:
; INHBWAIT (req) flag - 1 = wait before sending hb, 0 = send now
; INBPN background process number
; INBPNM background process name
; INDEBUG debug flag
; INIP array of socket parameters
; INIP("INIT") = msg to send (w/out SOM/EOM)
; CLISRV client/server flag
; INCHNL channel opened by calling routine
;
;Output:
; INHBSENT (pbr) # of hb's sent since last hb response
;
; Returns:
; 1 - successful
; 0 - unsuccessful (shutdown transceiver)
;
N INMSG,INMSGHDR,INMSGRTN
;
; Pace heartbeats
I $G(INHBWAIT) D Q:'INRUNMT 0 ; quit if shutdown signalled
. D:$G(INDEBUG) LOG^INHVCRA1("Waiting "_INIP("THNG")_" seconds to send heartbeat message",7)
. D WAIT^INHUVUT2(INBPN,INIP("THNG"),"Waiting "_INIP("THNG")_" seconds to send heartbeat message",.INRUNMT)
. S INRUNMT='INRUNMT ; wait rtns opposite
;
; Start transaction audit
D:$D(XUAUDIT) TTSTRT^XUSAUD("","",INBPNM,"","DUMMYTRX TRANSMIT")
;
S INMSG=INIP("INIT")
I INIP("CRYPT") D
. I INSTD="PDTS" D ; do not encrypt 1st hdr
.. S INMSGHDR=$P(INIP("INIT"),INIP("SOD")) ; save ENP hdr
.. S INMSG=$P(INIP("INIT"),INIP("SOD"),2,99999) ; msg to encrypt
. D ENCRYPT^INCRYPT(.INMSG,.INMSGRTN,$L(INMSG),1,1)
. S INMSG=INMSGRTN
. I (INSTD="PDTS") D
.. S INMSG=INMSGHDR_INIP("SOD")_INMSGRTN
.. S $E(INMSG,21,24)=$TR($J($L(INMSGRTN),4)," ","0") ; encrypted length
;
S INMSG=INIP("SOM")_INMSG_INIP("EOM")
;
S INRUNMT=$$INRHB^INHUVUT1(INBPN,"Sending heartbeat/dummy trx") Q:'INRUNMT 0
D SEND^%INET(INMSG,INCHNL,1)
;
; Post-send activities
S INHBSENT=INHBSENT+1
D:$G(INDEBUG) LOG^INHVCRA1("Sent heartbeat message",7)
D:$D(XUAUDIT) TTSTP^XUSAUD(0) ;stop transaction audit
Q 1
;
;
SHUTDWN(INBPN,INCHNL) ; Shutdown LoS
;
; Called by: INHVTMT
;
; Input:
; INBPN - (req) BACKGROUND PROCESS CONTROL IEN for LoS
; INCHNL - (opt) TCP channel assigned to this server when connection
; is opened
; Output:
; None.
;
D:$G(INDEBUG) LOG^INHVCRA1("SHUTDWN: Transceiver "_INBPNM,1)
D:$G(INDEBUG) LOG^INHVCRA1("Shutting down TCP socket transceiver for "_INBPNM,5)
; Reroute to the destination que all "pending response" que msgs
; Allow another transceiver to send these msgs while this transceiver
; is down.
D REROUTE^INHVTMT4(INDSTR,.INPEND)
D CLOSE
D:$G(INDEBUG) LOG^INHVCRA1("TCP socket transceiver is shutdown for "_INBPNM,5)
D DEBUG^INHVCRA1(0) ; turn debugging off
I $G(INIP("CRYPT")) S X=$$CRYPOFF^INCRYPT()
K ^UTILITY("INREC",$J),^UTILITY("INV",$J)
K ^INRHB("RUN",INBPN)
L -^INRHB("RUN",INBPN)
;Stop background process audit
D:$D(XUAUDIT) AUDSTP^XUSAUD
Q
;
CLOSE ; Close channel
;
; Called by: INHVTMT, SHUTDWN^INHVTMT5, ERR^INHVTMT5
;
; Input:
; INBPN - (req) BACKGROUND PROCESS CONTROL IEN for LoS
; INCHNL - (req) TCP channel assigned to this server when connection
; is opened
; Output:
; None.
I $G(INCHNL) D
. D:$G(INDEBUG) LOG^INHVCRA1("Closing connection for "_INBPNM,6)
. D CLOSE^%INET(INCHNL)
Q
;
ERR ;Error module
;
; Called by: Error Trap set at start of INHVTMT
;
N INREERR S INREERR=$$GETERR^%ZTOS
;Handle known non-fatal error conditions
I $$ETYPE^%ZTFE("O") D G EN^INHVTMT
.S X="ERR^INHVTMT5",@^%ZOSF("TRAP") D:$D(INCHNL) CLOSE^%INET(INCHNL)
.D:$G(INDEBUG) LOG^INHVCRA1("Non-fatal error encountered in "_INBPNM,6)
;If unanticipated error is encounterd close port and quit receiver
S:'$D(INBPNM) INBPNM=$P($G(^INTHPC(INBPN,0)),U) ; THIS SHOULD NOT HAPPEN
D ENR^INHE(INBPN,"Fatal error encountered by TRANSCEIVER - "_INREERR_" in background process "_INBPNM)
D:$G(INDEBUG) LOG^INHVCRA1("Fatal error encountered by TRANSCEIVER - "_INREERR_" in background process "_INBPNM,4)
I $D(INCHNL) D CLOSE^%INET(INCHNL)
I $G(INIP("CRYPT")) S X=$$CRYPOFF^INCRYPT()
D REROUTE^INHVTMT4(INDSTR,.INPEND)
K ^UTILITY("INREC",$J),^UTILITY("INV",$J)
K ^INRHB("RUN",INBPN)
L -^INRHB("RUN",INBPN)
;Stop background process audit
D:$D(XUAUDIT) AUDSTP^XUSAUD
X $G(^INTHOS(1,3))
D DEBUG^INHVCRA1(0)
Q
;
;
INHVTMT5 ; KAC ; 06 Aug 1999 15:34:58; Multi-threaded TCP/IP socket utilities
+1 ;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
+2 ;COPYRIGHT 1991-2000 SAIC
+3 QUIT
+4 ;
HB(INHBSENT,INHBWAIT) ; Function:
+1 ; Heartbeat/dummy msg sent to indicate when transceiver can start
+2 ; sending msgs from UNIVERSAL INTERFACE file. Adds SOM and EOM
+3 ; to start/end of msg.
+4 ;
+5 ; Called by: INHVTMT
+6 ;
+7 ;Input:
+8 ; INHBWAIT (req) flag - 1 = wait before sending hb, 0 = send now
+9 ; INBPN background process number
+10 ; INBPNM background process name
+11 ; INDEBUG debug flag
+12 ; INIP array of socket parameters
+13 ; INIP("INIT") = msg to send (w/out SOM/EOM)
+14 ; CLISRV client/server flag
+15 ; INCHNL channel opened by calling routine
+16 ;
+17 ;Output:
+18 ; INHBSENT (pbr) # of hb's sent since last hb response
+19 ;
+20 ; Returns:
+21 ; 1 - successful
+22 ; 0 - unsuccessful (shutdown transceiver)
+23 ;
+24 NEW INMSG,INMSGHDR,INMSGRTN
+25 ;
+26 ; Pace heartbeats
+27 ; quit if shutdown signalled
IF $GET(INHBWAIT)
Begin DoDot:1
+28 IF $GET(INDEBUG)
DO LOG^INHVCRA1("Waiting "_INIP("THNG")_" seconds to send heartbeat message",7)
+29 DO WAIT^INHUVUT2(INBPN,INIP("THNG"),"Waiting "_INIP("THNG")_" seconds to send heartbeat message",.INRUNMT)
+30 ; wait rtns opposite
SET INRUNMT='INRUNMT
End DoDot:1
IF 'INRUNMT
QUIT 0
+31 ;
+32 ; Start transaction audit
+33 IF $DATA(XUAUDIT)
DO TTSTRT^XUSAUD("","",INBPNM,"","DUMMYTRX TRANSMIT")
+34 ;
+35 SET INMSG=INIP("INIT")
+36 IF INIP("CRYPT")
Begin DoDot:1
+37 ; do not encrypt 1st hdr
IF INSTD="PDTS"
Begin DoDot:2
+38 ; save ENP hdr
SET INMSGHDR=$PIECE(INIP("INIT"),INIP("SOD"))
+39 ; msg to encrypt
SET INMSG=$PIECE(INIP("INIT"),INIP("SOD"),2,99999)
End DoDot:2
+40 DO ENCRYPT^INCRYPT(.INMSG,.INMSGRTN,$LENGTH(INMSG),1,1)
+41 SET INMSG=INMSGRTN
+42 IF (INSTD="PDTS")
Begin DoDot:2
+43 SET INMSG=INMSGHDR_INIP("SOD")_INMSGRTN
+44 ; encrypted length
SET $EXTRACT(INMSG,21,24)=$TRANSLATE($JUSTIFY($LENGTH(INMSGRTN),4)," ","0")
End DoDot:2
End DoDot:1
+45 ;
+46 SET INMSG=INIP("SOM")_INMSG_INIP("EOM")
+47 ;
+48 SET INRUNMT=$$INRHB^INHUVUT1(INBPN,"Sending heartbeat/dummy trx")
IF 'INRUNMT
QUIT 0
+49 DO SEND^%INET(INMSG,INCHNL,1)
+50 ;
+51 ; Post-send activities
+52 SET INHBSENT=INHBSENT+1
+53 IF $GET(INDEBUG)
DO LOG^INHVCRA1("Sent heartbeat message",7)
+54 ;stop transaction audit
IF $DATA(XUAUDIT)
DO TTSTP^XUSAUD(0)
+55 QUIT 1
+56 ;
+57 ;
SHUTDWN(INBPN,INCHNL) ; Shutdown LoS
+1 ;
+2 ; Called by: INHVTMT
+3 ;
+4 ; Input:
+5 ; INBPN - (req) BACKGROUND PROCESS CONTROL IEN for LoS
+6 ; INCHNL - (opt) TCP channel assigned to this server when connection
+7 ; is opened
+8 ; Output:
+9 ; None.
+10 ;
+11 IF $GET(INDEBUG)
DO LOG^INHVCRA1("SHUTDWN: Transceiver "_INBPNM,1)
+12 IF $GET(INDEBUG)
DO LOG^INHVCRA1("Shutting down TCP socket transceiver for "_INBPNM,5)
+13 ; Reroute to the destination que all "pending response" que msgs
+14 ; Allow another transceiver to send these msgs while this transceiver
+15 ; is down.
+16 DO REROUTE^INHVTMT4(INDSTR,.INPEND)
+17 DO CLOSE
+18 IF $GET(INDEBUG)
DO LOG^INHVCRA1("TCP socket transceiver is shutdown for "_INBPNM,5)
+19 ; turn debugging off
DO DEBUG^INHVCRA1(0)
+20 IF $GET(INIP("CRYPT"))
SET X=$$CRYPOFF^INCRYPT()
+21 KILL ^UTILITY("INREC",$JOB),^UTILITY("INV",$JOB)
+22 KILL ^INRHB("RUN",INBPN)
+23 LOCK -^INRHB("RUN",INBPN)
+24 ;Stop background process audit
+25 IF $DATA(XUAUDIT)
DO AUDSTP^XUSAUD
+26 QUIT
+27 ;
CLOSE ; Close channel
+1 ;
+2 ; Called by: INHVTMT, SHUTDWN^INHVTMT5, ERR^INHVTMT5
+3 ;
+4 ; Input:
+5 ; INBPN - (req) BACKGROUND PROCESS CONTROL IEN for LoS
+6 ; INCHNL - (req) TCP channel assigned to this server when connection
+7 ; is opened
+8 ; Output:
+9 ; None.
+10 IF $GET(INCHNL)
Begin DoDot:1
+11 IF $GET(INDEBUG)
DO LOG^INHVCRA1("Closing connection for "_INBPNM,6)
+12 DO CLOSE^%INET(INCHNL)
End DoDot:1
+13 QUIT
+14 ;
ERR ;Error module
+1 ;
+2 ; Called by: Error Trap set at start of INHVTMT
+3 ;
+4 NEW INREERR
SET INREERR=$$GETERR^%ZTOS
+5 ;Handle known non-fatal error conditions
+6 IF $$ETYPE^%ZTFE("O")
Begin DoDot:1
+7 SET X="ERR^INHVTMT5"
SET @^%ZOSF("TRAP")
IF $DATA(INCHNL)
DO CLOSE^%INET(INCHNL)
+8 IF $GET(INDEBUG)
DO LOG^INHVCRA1("Non-fatal error encountered in "_INBPNM,6)
End DoDot:1
GOTO EN^INHVTMT
+9 ;If unanticipated error is encounterd close port and quit receiver
+10 ; THIS SHOULD NOT HAPPEN
IF '$DATA(INBPNM)
SET INBPNM=$PIECE($GET(^INTHPC(INBPN,0)),U)
+11 DO ENR^INHE(INBPN,"Fatal error encountered by TRANSCEIVER - "_INREERR_" in background process "_INBPNM)
+12 IF $GET(INDEBUG)
DO LOG^INHVCRA1("Fatal error encountered by TRANSCEIVER - "_INREERR_" in background process "_INBPNM,4)
+13 IF $DATA(INCHNL)
DO CLOSE^%INET(INCHNL)
+14 IF $GET(INIP("CRYPT"))
SET X=$$CRYPOFF^INCRYPT()
+15 DO REROUTE^INHVTMT4(INDSTR,.INPEND)
+16 KILL ^UTILITY("INREC",$JOB),^UTILITY("INV",$JOB)
+17 KILL ^INRHB("RUN",INBPN)
+18 LOCK -^INRHB("RUN",INBPN)
+19 ;Stop background process audit
+20 IF $DATA(XUAUDIT)
DO AUDSTP^XUSAUD
+21 XECUTE $GET(^INTHOS(1,3))
+22 DO DEBUG^INHVCRA1(0)
+23 QUIT
+24 ;
+25 ;