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

Now only standard input, output, error, pipes and process streams are automatically unwatched.

[INTERPRETER]
* BUG: Now only standard input, output, error, pipes and process streams are automatically unwatched.
parent 3f5234be
Pipeline #351046158 failed with stage
in 27 minutes
......@@ -79,27 +79,41 @@ static GB_FUNCTION _term_resize_func;
static void callback_read(int fd, int type, CSTREAM *_object)
{
STREAM *stream = CSTREAM_TO_STREAM(_object);
STREAM *stream = CSTREAM_TO_STREAM(THIS);
int64_t len;
if (!stream->common.no_read_check)
if (!GB_CanRaise(THIS, EVENT_Read))
goto __DISABLE_WATCH;
STREAM_read_ahead(stream);
if (stream->common.check_read)
{
STREAM_read_ahead(stream);
if (!STREAM_lof_safe(stream, &len) && len == 0)
{
//fprintf(stderr, "callback_read: close watch\n");
GB_Watch(fd, GB_WATCH_READ, NULL, (intptr_t)_object);
stream->common.eof = TRUE;
return;
goto __DISABLE_WATCH;
}
}
GB_Raise(_object, EVENT_Read, 0);
if (!stream->common.eof)
GB_Raise(THIS, EVENT_Read, 0);
else
WATCH_little_sleep();
return;
__DISABLE_WATCH:
GB_Watch(fd, GB_WATCH_READ, NULL, (intptr_t)THIS);
}
static void callback_write(int fd, int type, CSTREAM *stream)
static void callback_write(int fd, int type, CSTREAM *_object)
{
GB_Raise(stream, EVENT_Write, 0);
if (GB_CanRaise(THIS, EVENT_Write))
GB_Raise(THIS, EVENT_Write, 0);
else
GB_Watch(fd, GB_WATCH_WRITE, NULL, (intptr_t)THIS);
}
static void cb_term_resize(int signum, intptr_t data)
......@@ -150,6 +164,7 @@ static CFILE *create_default_stream(FILE *file, int mode)
stream.type = &STREAM_buffer;
stream.common.no_read_ahead = tty;
stream.common.standard = TRUE;
stream.common.check_read = TRUE;
stream.buffer.file = file;
//stream.direct.fd = fileno(file);
STREAM_check_blocking(&stream);
......
......@@ -248,7 +248,7 @@ __OPEN:
stream->common.redirected = FALSE;
stream->common.no_read_ahead = FALSE;
stream->common.null_terminated = FALSE;
stream->common.no_read_check = FALSE;
stream->common.check_read = FALSE;
if ((*(sclass->open))(stream, path, mode, NULL))
THROW_SYSTEM(errno, path);
......
......@@ -71,7 +71,7 @@ typedef
unsigned redirected : 1;
unsigned no_read_ahead : 1;
unsigned null_terminated : 1;
unsigned no_read_check : 1;
unsigned check_read : 1;
unsigned _reserved : 3;
#if __WORDSIZE == 64
unsigned _reserved2 : 32;
......
......@@ -81,7 +81,6 @@ static int stream_open(STREAM *stream, const char *path, int mode)
{
stream->common.available_now = FALSE;
stream->common.no_read_ahead = TRUE;
stream->common.no_read_check = TRUE;
}
else
stream->common.available_now = TRUE;
......
......@@ -93,7 +93,6 @@ static int stream_open(STREAM *stream, const char *path, int mode)
stream->direct.watch = TRUE;
stream->common.no_read_ahead = TRUE;
stream->common.no_read_check = TRUE;
}
else
{
......@@ -120,12 +119,13 @@ static int stream_open(STREAM *stream, const char *path, int mode)
{
stream->common.available_now = FALSE;
stream->common.no_read_ahead = TRUE;
stream->common.no_read_check = TRUE;
stream->direct.has_size = TRUE;
fcntl(fd, F_SETFL, O_NONBLOCK);
}
else
{
stream->common.available_now = TRUE;
}
}
FD = fd;
......
......@@ -69,6 +69,7 @@ static int stream_open(STREAM *stream, const char *path, int mode)
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK);
stream->pipe.can_write = ((mode & GB_ST_MODE) & GB_ST_WRITE) != 0;
stream->common.check_read = TRUE;
FD = fd;
return FALSE;
......
......@@ -47,6 +47,7 @@
static int stream_open(STREAM *stream, const char *path, int mode, CPROCESS *process)
{
stream->process.process = process;
stream->common.check_read = TRUE;
STREAM_blocking(stream, FALSE);
return FALSE;
}
......
......@@ -492,13 +492,6 @@ void SUBR_instr(ushort code)
pp = PARAM[1]._string.addr + PARAM[1]._string.start;
pos = STRING_search(ps, ls, pp, lp, is, right, nocase);
/*pos2 = STRING_search2(ps, ls, pp, lp, is, right, nocase);
if (pos != pos2)
{
for(;;)
usleep(1000);
}*/
__FOUND:
......
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