[INTERPRETER]

* BUG: Disable read watch when reading a stream fails for any reason: i/o
  error, end-of-file...


git-svn-id: svn://localhost/gambas/trunk@5811 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2013-08-19 21:45:13 +00:00
parent 3d820edb15
commit 4830af856b

View file

@ -256,18 +256,21 @@ void STREAM_release(STREAM *stream)
STREAM_cancel(stream);
}
static void stop_watching(STREAM *stream, int mode)
{
int fd = STREAM_handle(stream);
if (fd >= 0)
GB_Watch(fd, mode, NULL, 0);
}
void STREAM_close(STREAM *stream)
{
int fd;
STREAM_release(stream);
if (!stream->type)
return;
fd = STREAM_handle(stream);
if (fd >= 0)
GB_Watch(fd, GB_WATCH_NONE, NULL, 0);
stop_watching(stream, GB_WATCH_NONE);
if (stream->common.standard || !(*(stream->type->close))(stream))
stream->type = NULL;
@ -319,10 +322,13 @@ void STREAM_read(STREAM *stream, void *addr, int len)
while ((*(stream->type->read))(stream, addr, len))
{
if (errno == EINTR)
continue;
stop_watching(stream, GB_WATCH_READ);
switch(errno)
{
case EINTR:
break;
case 0:
case EAGAIN:
THROW(E_EOF);
@ -355,10 +361,13 @@ char STREAM_getchar(STREAM *stream)
if (!ret)
break;
if (errno == EINTR)
continue;
stop_watching(stream, GB_WATCH_READ);
switch(errno)
{
case EINTR:
continue;
case 0:
case EAGAIN:
THROW(E_EOF);
@ -418,10 +427,13 @@ int STREAM_read_max(STREAM *stream, void *addr, int len)
if (!err)
break;
if (errno == EINTR)
continue;
stop_watching(stream, GB_WATCH_READ);
switch(errno)
{
case EINTR:
continue;
case 0:
case EAGAIN:
return STREAM_eff_read;
@ -550,10 +562,13 @@ static void fill_buffer(STREAM *stream, char *addr)
if (!err)
break;
if (errno == EINTR)
continue;
stop_watching(stream, GB_WATCH_READ);
switch(errno)
{
case EINTR:
continue;
case 0:
case EAGAIN:
case EINPROGRESS: