6 Input-Output Streams

Input-output streams capture bidirectional communications between GAP and another process, either locally or (@as yet unimplemented@) remotely

Such streams support the basic operations of both input and output streams. They should provide some buffering, allowing output date to be written to the stream, even when input data is waiting to be read, but the amount of this buffering is operating system dependent, and the user should take care not to get too far ahead in writing, or behind in reading, or deadlock may occur.

  • IsInputOutputStream C

    IsInputOutputStream is the Category of Input-Output Streams,

    At present the only type of Input-Output streams that are implemented provide communication with a local child process, using a pseudo-tty. They are only available on UNIX systems.

    At present, all operations on these streams are non-blocking, and will read or write as much of the requested data as possible immediately, but will not wait, for instance, for the child process to clear its input buffers. This may be reviewed. The GAP kernel functions used to implement these streams do support blocking operation, and this may be made available later. In non-blocking operation, ReadByte will return fail if no byte is available, and ReadLine and ReadAll may return only the bytes that were available. WriteByte, WriteLine and WriteAll will return fail if they did not succeed in writing all that they were asked to.

    As far as possible, no translation is done on characters written to, or read from the stream, and no control characters have special effects, but the details of particular pseudo-tty implementations may effect this. The stream may try to read more characters from the child than the user requests in a ReadByte or ReadLine call, and store them up to handle subsequent reads more quickly, but will not block waiting for such characters. All characters written are delivered immediately to the pseudo-tty.

  • InputOutputLocalProcess( current-dir, executable, args ) F

    Calling InputOutputLocalProcess( current-dir, executable, args ) starts up a slave process, whose executable file is executable, with ``command line' arguments args and current directory current-dir. It returns an InputOutputStream object. Bytes written to this stream are received by the slave process as if typed at a terminal on standard input. Bytes written to standard output by the slave process can be read from the stream (some buffering of reads, but not writes may be done by the stream).

    When the stream if closed, the signal SIGTERM is delivered to the child process, which is expected to exit.

    gap> d := DirectoryCurrent();
    dir("./")
    gap> f := Filename(DirectoriesSystemPrograms(), "rev");
    "/usr/bin/rev"
    gap> s := InputOutputLocalProcess(d,f,[]);
    < input/output stream to rev >
    gap> WriteLine(s,"The cat sat on the mat");
    true
    gap> Print(ReadLine(s));
    tam eht no tas tac ehT
    gap> ReadLine(s);
    failgap> x := ListWithIdenticalEntries(10000,'x');;
    gap> ConvertToStringRep(x);
    gap> WriteLine(s,x);
    fail
    gap> WriteByte(s,INT_CHAR('\n'));
    true
    gap> y := ReadAll(s);;
    gap> Length(y);      
    4096
    gap> CloseStream(s);
    gap> s;
    < closed input/output stream to rev >
    

    Sections

    [Top] [Previous] [Up] [Index]

    GAP 4 manual
    September 2000