Changeset: a7ffb37fdf0b for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a7ffb37fdf0b Modified Files: common/stream/stream.c common/stream/stream.h monetdb5/mal/mal_client.c Branch: default Log Message:
Implemented a MNSTR_TIMEOUT error type for streams. When a read timeout is set (mnstr_settimeout() on a read stream), socket reads may time out. If they do, they return an error and set mnstr_errnr() to MNSTR_TIMEOUT (or they return the data read so far, if any). Upper layers will need to deal with this. One instance of this has been implemented. (Note, we don't actually set the timeout yet.) diffs (75 lines): diff --git a/common/stream/stream.c b/common/stream/stream.c --- a/common/stream/stream.c +++ b/common/stream/stream.c @@ -502,6 +502,9 @@ error(stream *s) case MNSTR_WRITE_ERROR: snprintf(buf, BUFSIZ, "error writing file %s\n", s->name); return strdup(buf); + case MNSTR_TIMEOUT: + snprintf(buf, BUFSIZ, "timeout on %s\n", s->name); + return strdup(buf); } return strdup("Unknown error"); } @@ -1518,7 +1521,10 @@ socket_write(stream *s, const void *buf, if ((size_t) res >= elmsize) return (ssize_t) (res / elmsize); if (nr < 0) { - s->errnr = MNSTR_WRITE_ERROR; + if (s->timeout > 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) + s->errnr = MNSTR_TIMEOUT; + else + s->errnr = MNSTR_WRITE_ERROR; return -1; } return 0; @@ -1546,7 +1552,10 @@ socket_read(stream *s, void *buf, size_t nr = read(s->stream_data.s, (char *) buf + s->len, size - s->len); #endif if (nr == -1) { - s->errnr = MNSTR_READ_ERROR; + if (s->timeout > 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) + s->errnr = MNSTR_TIMEOUT; + else + s->errnr = MNSTR_READ_ERROR; return -1; } if (nr == 0) diff --git a/common/stream/stream.h b/common/stream/stream.h --- a/common/stream/stream.h +++ b/common/stream/stream.h @@ -236,7 +236,8 @@ typedef enum mnstr_errors { MNSTR_NO__ERROR = 0, MNSTR_OPEN_ERROR, MNSTR_READ_ERROR, - MNSTR_WRITE_ERROR + MNSTR_WRITE_ERROR, + MNSTR_TIMEOUT } mnstr_errors; #endif /*_STREAM_H_*/ diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c --- a/monetdb5/mal/mal_client.c +++ b/monetdb5/mal/mal_client.c @@ -526,7 +526,20 @@ MCreadClient(Client c) mnstr_flush(c->fdout); in->eof = 0; } - while ((rd = bstream_next(in)) > 0 && !in->eof) { + for (;;) { + rd = bstream_next(in); + if (GDKexiting()) + return 0; + if (rd < 0) { + if (mnstr_errnr(in->s) == MNSTR_TIMEOUT) { + mnstr_clearerr(in->s); + continue; + } + /* read error */ + return 0; + } + if (in->eof) + break; sum += rd; if (!in->mode) /* read one line at a time in line mode */ break; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list