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

Some fixes in stream management.

[INTERPRETER]
* NEW: Read watches are automatically disabled when stream is closed in all cases.
* BUG: Buffered stream end-of-file function has been fixed.
parent 45b3e175
Pipeline #343253305 passed with stage
in 24 minutes and 26 seconds
......@@ -77,13 +77,21 @@ static SIGNAL_CALLBACK *_SIGWINCH_callback = NULL;
static GB_FUNCTION _term_resize_func;
static void callback_read(int fd, int type, CSTREAM *stream)
static void callback_read(int fd, int type, CSTREAM *_object)
{
if (!STREAM_read_ahead(CSTREAM_TO_STREAM(stream)))
GB_Raise(stream, EVENT_Read, 0);
STREAM *stream = CSTREAM_TO_STREAM(_object);
int64_t lof;
STREAM_read_ahead(stream);
STREAM_lof(stream, &lof);
if (lof > 0)
GB_Raise(_object, EVENT_Read, 0);
else
GB_Watch(fd, GB_WATCH_READ, NULL, (intptr_t)stream);
//WATCH_little_sleep();
{
GB_Watch(fd, GB_WATCH_READ, NULL, (intptr_t)_object);
stream->common.eof = TRUE;
}
}
static void callback_write(int fd, int type, CSTREAM *stream)
......@@ -141,6 +149,7 @@ static CFILE *create_default_stream(FILE *file, int mode)
stream.common.no_read_ahead = tty;
stream.common.standard = TRUE;
stream.buffer.file = file;
//stream.direct.fd = fileno(file);
STREAM_check_blocking(&stream);
return (CFILE *)OBJECT_REF(CFILE_create(&stream, mode));
}
......
......@@ -755,7 +755,7 @@ bool STREAM_read_ahead(STREAM *stream)
ALLOC(&extra->buffer, STREAM_BUFFER_SIZE);
eff = fill_buffer(stream, extra->buffer, TRUE);
extra->buffer_pos = 0;
extra->buffer_len = eff;
......
......@@ -113,34 +113,6 @@ static int stream_read(STREAM *stream, char *buffer, int len)
}
return eff;
/*
while (len > 0)
{
len_read = Min(len, MAX_IO);
eff_read = fread(buffer, 1, len_read, FD);
if (eff_read > 0)
{
STREAM_eff_read += eff_read;
len -= eff_read;
buffer += eff_read;
}
if (eff_read < len_read)
{
if (feof(FD))
{
errno = 0;
return TRUE;
}
if (ferror(FD) && errno != EINTR)
return TRUE;
}
}
return FALSE;
*/
}
......@@ -159,26 +131,6 @@ static int stream_write(STREAM *stream, char *buffer, int len)
return TRUE;
return fwrite(buffer, 1, len, FD);
/*while (len > 0)
{
len_write = Min(len, MAX_IO);
eff_write = fwrite(buffer, 1, len_write, FD);
if (eff_write < len_write)
{
if (ferror(FD) && errno != EINTR)
return TRUE;
}
len -= eff_write;
buffer += eff_write;
}
if (EXEC_debug)
return stream_flush(stream);
else
return FALSE;*/
}
......@@ -203,7 +155,9 @@ static int stream_tell(STREAM *stream, int64_t *pos)
static int stream_eof(STREAM *stream)
{
int c;
return !FD || feof(FD);
/*int c;
if (!FD)
return TRUE;
......@@ -213,7 +167,7 @@ static int stream_eof(STREAM *stream)
return TRUE;
ungetc(c, FD);
return FALSE;
return FALSE;*/
}
......
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