From 4830af856bbd9725b0e055d1c496bfaa62a441a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Mon, 19 Aug 2013 21:45:13 +0000 Subject: [PATCH] [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 --- main/gbx/gbx_stream.c | 45 ++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/main/gbx/gbx_stream.c b/main/gbx/gbx_stream.c index 2f3c51f1b..d09051a49 100644 --- a/main/gbx/gbx_stream.c +++ b/main/gbx/gbx_stream.c @@ -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); @@ -417,11 +426,14 @@ 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; @@ -549,11 +561,14 @@ 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: