Operating System - OpenVMS
1828028 Members
1891 Online
109973 Solutions
New Discussion

Re: Fortran program hangs when writing to offline reverse TNA device

 
SOLVED
Go to solution
R_B_W
Visitor

Fortran program hangs when writing to offline reverse TNA device

Hi All,

I've recently inherited our VMS system and I'm running into problems when a fortran program tries to write to a reverse TNA device that is offline at the device end (e.g. powered off, network outage). These still show up as online when using:
>show dev tna
(Which I believe to be property of reverse telnet devices.)

The TNA devices are opened in fortran using the standard Open() function and are written to using the standard write() function. 

Ideally the write function, or underlying tcp, would hit a timeout/error condition and return an iostat which can be handled and the program can continue. 

I've read through the available documentation on fortran and tcpip but haven't found anything I think is relevant.

Any ideas on how I can prevent the program hanging? Thanks!

Running: 
OpenVMS 8.4-2  
TCPIP V5.7 - ECO5
VSI Fortran V8.3

Apologies if this is poorly worded/explained, I'm new to both VMS and software management.

Cheers,

RBW 

5 REPLIES 5
Volker Halle
Honored Contributor
Solution

Re: Fortran program hangs when writing to offline reverse TNA device

RBW,

AFAIK a write with timeout cannot be done with standard FORTRAN statements.

You have 2 alternatives. both require OpenVMS programming skills and changes to your source code:

- use USEROPEN and set RAB$V_TMO and RAB$B_TMO

see VSI Fortran for OpenVMS User Manual — VMS Software, Inc.

- use QIOs with a timer, ASTs and/or event flags

Volker.

R_B_W
Visitor

Re: Fortran program hangs when writing to offline reverse TNA device

Thanks for the leads Volker! I'll accept this as the solution until I get around to testing/confirming useropen.

Cheers,

RBW

Tom Wade_1
Occasional Advisor

Re: Fortran program hangs when writing to offline reverse TNA device

Hi,

I did something similar with useropen to set the wait-for-lock bit.  I've modified this slightly to use the timeout bit to produce a demo program.  Hopefully this will help.  It does I/O to the terminal using Fortran Read/Write.  If the read times out, it will exit with an error.

Tom Wade

C   Program to demonstrate timeout I/O

        Program Demo_Timeout

        Implicit None
        Integer         status, unit, length
        Character *256  line
        Integer         Set_Timeout_IO
        External        Set_Timeout_IO

        Call Lib$Get_LUN (unit)
        Open (unit, name='SYS$COMMAND', status='old', useropen=Set_Timeout_IO)

C   Write and read some data.

        Write (unit, 21, err=80)
21      Format (' This is some data')
        Read (unit, 11, err=80) length, line
11      Format (Q, A)
        Write (unit, 22, err=80) line (1:length)
22      Format (' Read "', A, '"')
        Close (unit)
        Call Lib$Free_Lun (unit)
        Call Exit

C  Error branch

80      Call Errsns (,status,,,)
        Call Exit (status)
        End

C+
        Integer Function Set_Timeout_IO (fab, rab, unit)

C  Open the file described by File Access Block 'fab', Record Access Block
C  'rab' and logical unit number 'unit'.  We open the file so that all I/O
C  is subject to a timeout.
C-
        Integer         unit, status
        Include         '($FABDEF)'
        Include         '($RABDEF)'
        Include         '($SYSSRVNAM)'
        Record  /FABDEF/        fab
        Record  /RABDEF/        rab


C   Set the required bit for timeout

        rab.Rab$L_Rop = rab.Rab$L_Rop .or. Rab$M_Tmo

C   Set the timeout period

        rab.Rab$B_Tmo = 5               ! seconds


C   Open the file.

        status = Sys$Open (fab)

        If (status) status = Sys$Connect (rab)

C   Return status

        Set_Timeout_IO = status
        End

  

R_B_W
Visitor

Re: Fortran program hangs when writing to offline reverse TNA device

Hi Tom,

Thanks for the code, I have a similar test program based on the info Volker directed me to. It seems to me the timeout only concerns reads and not writes, my program will still hang indefinitely when I write to the device and it's off. 

 

c
        Program test_useropen
c
        integer         iostat,ierr,sysfil
        external        timeout_config
c
        sysfil = 10000
c
        Print *, 'opening device'
        OPEN (UNIT=SYSFIL, 
        1       STATUS='OLD', 
        1       SHARED,
        1       ACCESS='APPEND',
        1       FILE='FIL',         ! FIL is a system logical = TNA101:
        1       IOSTAT=IOSTAT,
        1       FORM='FORMATTED',
        1       USEROPEN=TIMEOUT_CONFIG)
        Print *, 'open status: ',iostat
c
c
        Print *, 'starting write'
        write(sysfil,fmt=10,iostat=iostat)
10      format(1x,'testing writing to an offline device')
        Print *, 'finished or skipped write with status: ',iostat
        close(sysfil)
c
        END
c
c
        Integer Function Timeout_config(FAB,RAB,LUN)
c
        Include '($FABDEF)'
        Include '($RABDEF)'
        Include '($SYSSRVNAM)'
c
        Record /FABDEF/ FAB
        Record /RABDEF/ RAB
c
        RAB.RAB$L_ROP = IBSET(RAB.RAB$L_ROP,RAB$V_TMO) 
        RAB.RAB$B_TMO = 5
c
        Timeout_config = sys$open(fab)
        IF (.not. timeout_config) RETURN
        Timeout_config = sys$connect(rab)
c
        Return
        END
c

 

 

Cheers,

RBW

Volker Halle
Honored Contributor

Re: Fortran program hangs when writing to offline reverse TNA device

RBW,

as the RAB$V_TMO mechanism does not seem to work on WRITE - see above examples - I checked the DCL READ and WRITE statements. There is a /TIME_OUT=n parameter for READ, but not for WRITE. This might mean, that a timeout for a RMS WRITE operation is not implemented - except for a timeout on a record lock.

So the best approch would be to write a subroutine, which uses QIOs and TIMER ASTs

See previous discussion of a similar questions in 

Re: SYS$QIOW doesn't return to caller - Hewlett Packard Enterprise Community (hpe.com)

Volker.