- BGUTCP ; IHS/OIT/MJL - Primary Control TCP listener ;
- ;;1.5;BGU;;MAY 26, 2005
- ;;Primary TCP Utility to start and stop Listener
- ;;BGUTSKT is the Socket port number for listening
- ;;
- EN ;EP-- entry point for interactive use
- N X1,X2,BGUTDBG S:'$D(DTIME) DTIME=300
- D EN^DDIOL("Enter client address: ") R X1:DTIME Q:'$T Q:X1="^"
- D EN^DDIOL(" Enter client port: ") R X2:DTIME Q:'$T Q:X2="^"
- S BGUTDBG=""
- D EN^BGUTCPH(X1,X2)
- Q
- STRT(BGUTSKT) D EN^DDIOL("Start TCP Listener...") ;EP--entry point for starting listener
- S U="^" D HOME^%ZIS
- STRTEN ;EP-- entry point for starting from startup
- I $G(BGUTSKT)="" S BGUTSKT=$G(^BGUSP(1,2),8000) ;default port
- ; -- see if 'running flag' for listener is set
- L +^BGUSP("TMP","RUNNING"):1
- I '$T D EN^DDIOL("TCP Listener appears to be running already.") Q
- L -^BGUSP("TMP","RUNNING"):1
- ;
- ; -- set stop flag to false and start the listener
- S ^BGUSP("TMP","STOP")=""
- ;D GETENV^%ZOSV
- ; -- START listener
- D
- .J EN^BGUTCPL(BGUTSKT)::5
- I '$T D EN^DDIOL("Unable to run TCP Listener in background.") Q
- D EN^DDIOL("TCP Listener started successfully.")
- Q
- ;
- STOAP(BGUTSKT) D EN^DDIOL("Stop TCP Listener...") ;EP--entry point for stoping listener
- ;
- I $G(BGUTSKT)="" S BGUTSKT=8000 ;default port
- ; -- make sure the listener is running
- L +^BGUSP("TMP","RUNNING"):1
- I $T D Q
- . L -^BGUSP("TMP","RUNNING"):1
- . D EN^DDIOL("TCP Listener does not appear to be running.")
- ;
- ; -- set the stop flag
- S ^BGUSP("TMP","STOP")=1
- ;
- ; -- send the shutdown message to the TCP Listener process
- S BGUVER=$G(^%ZOSF("OS")) S:'$L(BGUVER) BGUVER=$ZV
- S BGUMSM=$S(BGUVER["MSM":1,1:0)
- I BGUMSM D
- .O 56 U 56::"TCP"
- .W /SOCKET("127.0.0.1",BGUTSKT) ; -- connect to this machine
- .W $C(11),"TCPshutdown",! ; -- send the shutdown message
- .R X#3:5 ; -- get the three char 'ack' back
- .C 56
- I 'BGUMSM D
- .D CALL^%ZISTCP("127.0.0.1",BGUTSKT)
- .U IO
- .W $C(11),"TCPshutdown",! ; -- send the shutdown message
- .R X#3:5 ; -- get the three char 'ack' back
- .;C IO
- .;D CLOSE^%ZISTCP
- D EN^DDIOL("TCP Listener has been shutdown.")
- Q
- ;
- STOP(BGUTSKT) ;EP--entry point for stop TCP Listener. Interactive and TaskMan entry point
- STPEN ;EP -- entry point for stopping from option
- I $G(BGUTSKT)="" S BGUTSKT=$G(^BGUSP(1,2),8000) ;default port
- ;N IP,REF,X,DEV,XWBOS,XWBIP
- S U="^" D HOME^%ZIS
- D EN^DDIOL("Stop TCP Listener...")
- X ^%ZOSF("UCI") S REF=Y
- S IP="0.0.0.0" ;get server IP
- S XWBOS=$S(^%ZOSF("OS")["DSM":"DSM",^("OS")["MSM":"MSM",^("OS")["OpenM":"OpenM",1:"") ;RWF
- ;
- I $G(BGUTSKT)="" S BGUTSKT=8000 ;default port
- ; -- make sure the listener is running
- L +^BGUSP("TMP","RUNNING"):1
- I $T D Q
- . L -^BGUSP("TMP","RUNNING"):1
- . D EN^DDIOL("TCP Listener does not appear to be running.")
- ;
- ; -- set the stop flag
- S ^BGUSP("TMP","STOP")=1
- ;
- ; -- send the shutdown message to the TCP Listener process
- ; using loopback address
- S XWBTSKT=BGUTSKT
- S XWBIP="127.0.0.1"
- D CALL^%ZISTCP("127.0.0.1",XWBTSKT) I POP D Q
- . D EN^DDIOL("TCP Listener does not appear to be running.")
- U IO
- ;
- W $C(11),"TCPshutdown",! ; -- send the shutdown message
- R X#3:5
- D EN^DDIOL("TCP Listener Response to Shutdown Request: "_X)
- D CLOSE^%ZISTCP
- IF X="ack" D EN^DDIOL("TCP Listener has been shutdown.")
- ELSE D EN^DDIOL("Shutdown Failed!")
- ;change process name
- ;D CHPRN^XWBTCPC($J)
- Q
- RESTART(BGUTSKT) ;STOPS AND STARTS LISTENER
- D STOP(BGUTSKT)
- H 2
- D STRT(BGUTSKT)
- Q
- BGUTCP ; IHS/OIT/MJL - Primary Control TCP listener ;
- +1 ;;1.5;BGU;;MAY 26, 2005
- +2 ;;Primary TCP Utility to start and stop Listener
- +3 ;;BGUTSKT is the Socket port number for listening
- +4 ;;
- EN ;EP-- entry point for interactive use
- +1 NEW X1,X2,BGUTDBG
- IF '$DATA(DTIME)
- SET DTIME=300
- +2 DO EN^DDIOL("Enter client address: ")
- READ X1:DTIME
- IF '$TEST
- QUIT
- IF X1="^"
- QUIT
- +3 DO EN^DDIOL(" Enter client port: ")
- READ X2:DTIME
- IF '$TEST
- QUIT
- IF X2="^"
- QUIT
- +4 SET BGUTDBG=""
- +5 DO EN^BGUTCPH(X1,X2)
- +6 QUIT
- STRT(BGUTSKT) ;EP--entry point for starting listener
- DO EN^DDIOL("Start TCP Listener...")
- +1 SET U="^"
- DO HOME^%ZIS
- STRTEN ;EP-- entry point for starting from startup
- +1 ;default port
- IF $GET(BGUTSKT)=""
- SET BGUTSKT=$GET(^BGUSP(1,2),8000)
- +2 ; -- see if 'running flag' for listener is set
- +3 LOCK +^BGUSP("TMP","RUNNING"):1
- +4 IF '$TEST
- DO EN^DDIOL("TCP Listener appears to be running already.")
- QUIT
- +5 LOCK -^BGUSP("TMP","RUNNING"):1
- +6 ;
- +7 ; -- set stop flag to false and start the listener
- +8 SET ^BGUSP("TMP","STOP")=""
- +9 ;D GETENV^%ZOSV
- +10 ; -- START listener
- +11 Begin DoDot:1
- +12 JOB EN^BGUTCPL(BGUTSKT)::5
- End DoDot:1
- +13 IF '$TEST
- DO EN^DDIOL("Unable to run TCP Listener in background.")
- QUIT
- +14 DO EN^DDIOL("TCP Listener started successfully.")
- +15 QUIT
- +16 ;
- STOAP(BGUTSKT) ;EP--entry point for stoping listener
- DO EN^DDIOL("Stop TCP Listener...")
- +1 ;
- +2 ;default port
- IF $GET(BGUTSKT)=""
- SET BGUTSKT=8000
- +3 ; -- make sure the listener is running
- +4 LOCK +^BGUSP("TMP","RUNNING"):1
- +5 IF $TEST
- Begin DoDot:1
- +6 LOCK -^BGUSP("TMP","RUNNING"):1
- +7 DO EN^DDIOL("TCP Listener does not appear to be running.")
- End DoDot:1
- QUIT
- +8 ;
- +9 ; -- set the stop flag
- +10 SET ^BGUSP("TMP","STOP")=1
- +11 ;
- +12 ; -- send the shutdown message to the TCP Listener process
- +13 SET BGUVER=$GET(^%ZOSF("OS"))
- IF '$LENGTH(BGUVER)
- SET BGUVER=$ZV
- +14 SET BGUMSM=$SELECT(BGUVER["MSM":1,1:0)
- +15 IF BGUMSM
- Begin DoDot:1
- +16 OPEN 56
- USE 56::"TCP"
- +17 ; -- connect to this machine
- WRITE /SOCKET("127.0.0.1",BGUTSKT)
- +18 ; -- send the shutdown message
- WRITE $CHAR(11),"TCPshutdown",!
- +19 ; -- get the three char 'ack' back
- READ X#3:5
- +20 CLOSE 56
- End DoDot:1
- +21 IF 'BGUMSM
- Begin DoDot:1
- +22 DO CALL^%ZISTCP("127.0.0.1",BGUTSKT)
- +23 USE IO
- +24 ; -- send the shutdown message
- WRITE $CHAR(11),"TCPshutdown",!
- +25 ; -- get the three char 'ack' back
- READ X#3:5
- +26 ;C IO
- +27 ;D CLOSE^%ZISTCP
- End DoDot:1
- +28 DO EN^DDIOL("TCP Listener has been shutdown.")
- +29 QUIT
- +30 ;
- STOP(BGUTSKT) ;EP--entry point for stop TCP Listener. Interactive and TaskMan entry point
- STPEN ;EP -- entry point for stopping from option
- +1 ;default port
- IF $GET(BGUTSKT)=""
- SET BGUTSKT=$GET(^BGUSP(1,2),8000)
- +2 ;N IP,REF,X,DEV,XWBOS,XWBIP
- +3 SET U="^"
- DO HOME^%ZIS
- +4 DO EN^DDIOL("Stop TCP Listener...")
- +5 XECUTE ^%ZOSF("UCI")
- SET REF=Y
- +6 ;get server IP
- SET IP="0.0.0.0"
- +7 ;RWF
- SET XWBOS=$SELECT(^%ZOSF("OS")["DSM":"DSM",^("OS")["MSM":"MSM",^("OS")["OpenM":"OpenM",1:"")
- +8 ;
- +9 ;default port
- IF $GET(BGUTSKT)=""
- SET BGUTSKT=8000
- +10 ; -- make sure the listener is running
- +11 LOCK +^BGUSP("TMP","RUNNING"):1
- +12 IF $TEST
- Begin DoDot:1
- +13 LOCK -^BGUSP("TMP","RUNNING"):1
- +14 DO EN^DDIOL("TCP Listener does not appear to be running.")
- End DoDot:1
- QUIT
- +15 ;
- +16 ; -- set the stop flag
- +17 SET ^BGUSP("TMP","STOP")=1
- +18 ;
- +19 ; -- send the shutdown message to the TCP Listener process
- +20 ; using loopback address
- +21 SET XWBTSKT=BGUTSKT
- +22 SET XWBIP="127.0.0.1"
- +23 DO CALL^%ZISTCP("127.0.0.1",XWBTSKT)
- IF POP
- Begin DoDot:1
- +24 DO EN^DDIOL("TCP Listener does not appear to be running.")
- End DoDot:1
- QUIT
- +25 USE IO
- +26 ;
- +27 ; -- send the shutdown message
- WRITE $CHAR(11),"TCPshutdown",!
- +28 READ X#3:5
- +29 DO EN^DDIOL("TCP Listener Response to Shutdown Request: "_X)
- +30 DO CLOSE^%ZISTCP
- +31 IF X="ack"
- DO EN^DDIOL("TCP Listener has been shutdown.")
- +32 IF '$TEST
- DO EN^DDIOL("Shutdown Failed!")
- +33 ;change process name
- +34 ;D CHPRN^XWBTCPC($J)
- +35 QUIT
- RESTART(BGUTSKT) ;STOPS AND STARTS LISTENER
- +1 DO STOP(BGUTSKT)
- +2 HANG 2
- +3 DO STRT(BGUTSKT)
- +4 QUIT