Commit cba7b188 authored by Benoît Minisini's avatar Benoît Minisini
Browse files

Fix the behaviour of standard input, end of file and stream read watches.

[INTERPRETER]
* NEW: Standard input is not supposed to be always available for reading.
* NEW: Watching a stream for reading is stopped as soon as reading ahead returns end of file.
* NEW: Eof() now immediately returns TRUE if a previous read ahead has reached end of file.
parent a56d8192
Pipeline #338034122 passed with stage
in 23 minutes and 40 seconds
......@@ -82,7 +82,8 @@ static void callback_read(int fd, int type, CSTREAM *stream)
if (!STREAM_read_ahead(CSTREAM_TO_STREAM(stream)))
GB_Raise(stream, EVENT_Read, 0);
else
WATCH_little_sleep();
GB_Watch(fd, GB_WATCH_READ, NULL, (intptr_t)stream);
//WATCH_little_sleep();
}
static void callback_write(int fd, int type, CSTREAM *stream)
......@@ -136,7 +137,7 @@ static CFILE *create_default_stream(FILE *file, int mode)
CLEAR(&stream);
stream.type = &STREAM_buffer;
stream.common.available_now = !tty;
//stream.common.available_now = !tty;
stream.common.no_read_ahead = tty;
stream.common.standard = TRUE;
stream.buffer.file = file;
......@@ -173,7 +174,7 @@ void CFILE_init_watch(void)
{
//fprintf(stderr, "watch stdin\n");
//CFILE_in->watch_fd = STDIN_FILENO;
GB_Watch(STDIN_FILENO, GB_WATCH_READ, (void *)callback_read, (intptr_t)CFILE_in);
GB_Watch(fileno(stdin), GB_WATCH_READ, (void *)callback_read, (intptr_t)CFILE_in);
}
}
......
......@@ -1966,6 +1966,9 @@ bool STREAM_eof(STREAM *stream)
if (extra->buffer && extra->buffer_pos < extra->buffer_len)
return FALSE;
}
if (stream->common.eof)
return TRUE;
if (stream->type->eof)
return ((*(stream->type->eof))(stream));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment