This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Read FIFO blocked with gfortran (vs ifort)


 Hello,

Good news the problem has been identified.

I've refactored the FIFO read so that it is much more flexible and elegant.

(As a consequence, read_string_message call is replaced by
read_until_prompt.
"""""""""""""""""
call open_fifo()
print *, "Fifo opened..."

!call read_string_message(string_message, 8)
call read_until_prompt(string_message)
"""""""""""""""""
)
IOSTAT is not used because I've read that EOF and EOR values are not
standardized.
(It doesn't change anything about gfortran issue)

Best regards,

Cyril.


""""""""""""""""""""""""""""""""""""
        ! Open fifo
        subroutine open_fifo()
            open(11, file="input.fifo", action="write", status="old")
            print *, "  input.fifo opened"
            open(10, file="output.fifo", action="read", status="old")
            print *, "  output.fifo opened"
        end subroutine open_fifo
""""""""""""""""""""""""""""""""""""
        subroutine read_until_prompt(last_line)
            character(len=100), intent(out) :: last_line

            integer :: ncount, nc
            character :: c
            character(len=100) :: string_message
           
            string_message = ""
            ncount = 0
            nc = 0
            do
                read(10, '(a1)', advance="no", eor=888, end=999) c
!                write(*, '(a1)', advance='no') c
                nc = nc + 1
                string_message(nc:nc) = c
                cycle
 888            ncount = ncount + 1
!                write(*, *)
                ncount = ncount + 1
                if (is_prompt(string_message)) then
                    exit
                endif
                last_line = string_message
                string_message = ""
                nc = 0
                cycle
 999            exit
            enddo
        end subroutine read_until_prompt
"""""""""""""""""""""""""""""""""""

Le 30/09/2010 05:31, Jerry DeLisle a écrit :
> On 09/29/2010 07:42 AM, Tobias Burnus wrote:
> === snip ===
>> b) Without GFORTRAN_UNBUFFERED_ALL= it stops already with
>>    6/  8>              ** Creation Date: Wed Sep 29 15:33:01 CEST 2010
>>
>>    if (isatty (s->fd) || options.all_unbuffered
>>        ||(options.unbuffered_preconnected&&
>>           (s->fd == STDIN_FILENO
>>            || s->fd == STDOUT_FILENO
>>            || s->fd == STDERR_FILENO)))
>>      raw_init (s);
>>    else
>>      buf_init (s);
>>
>> I wonder whether one should not also add "!is_seekable(s->fd)" to those
>> items which are by default unbuffert.
>>
>
> I have looked this through.  The issue is unrelated to raw_init or
> buf_init above.  The issue is that we do not open files with
> O_NONBLOCK.  I can easily do that.
>
> We need to decide under what circumstances we should open with
> O_NONBLOCK.  In the example, the first call to read (man 3) returns
> with 282 bytes. The next call to read is blocking and nevr returns, it
> is waiting for input.
>
> I have ngspice set up here so I can explore all this further. Using
> O_NONBLOCK in unix.c, I get the folllowing:
>
> $ ./a.out
>    input.fifo opened
>    output.fifo opened
>  Fifo opened...
> At line 81 of file spicy.f90 (unit = 10, file = 'output.fifo')
> Fortran runtime error: End of file
> $
>
> So in this case with non blocking, the read returns right away with
> nothing and we interpret that as an end of file.
>
> So what I think we need to do is special case FIFO.  I will give this
> some further thought and see if I can come up with a patch.  I have
> filed PR45839.
>
> Jerry


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]