diff options
Diffstat (limited to 'camel/camel-stream-fs.c')
-rw-r--r-- | camel/camel-stream-fs.c | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/camel/camel-stream-fs.c b/camel/camel-stream-fs.c index b2eb9d5050..a1d7cbaca3 100644 --- a/camel/camel-stream-fs.c +++ b/camel/camel-stream-fs.c @@ -242,16 +242,20 @@ stream_read (CamelStream *stream, char *buffer, size_t n) FD_SET (cancel_fd, &rdset); fdmax = MAX (stream_fs->fd, cancel_fd) + 1; - select (fdmax, &rdset, 0, 0, NULL); - if (FD_ISSET (cancel_fd, &rdset)) { - fcntl (stream_fs->fd, F_SETFL, flags); - errno = EINTR; - return -1; + nread = -1; + if (select (fdmax, &rdset, 0, 0, NULL) != -1) { + if (FD_ISSET (cancel_fd, &rdset)) { + fcntl (stream_fs->fd, F_SETFL, flags); + errno = EINTR; + return -1; + } + + do { + nread = read (stream_fs->fd, buffer, n); + } while (nread == -1 && errno == EAGAIN); + } else if (errno == EINTR) { + errno = EAGAIN; } - - do { - nread = read (stream_fs->fd, buffer, n); - } while (nread == -1 && errno == EAGAIN); } while (nread == -1 && errno == EAGAIN); error = errno; @@ -307,31 +311,37 @@ stream_write (CamelStream *stream, const char *buffer, size_t n) FD_SET (stream_fs->fd, &wrset); FD_SET (cancel_fd, &rdset); - select (fdmax, &rdset, &wrset, 0, NULL); - if (FD_ISSET (cancel_fd, &rdset)) { - fcntl (stream_fs->fd, F_SETFL, flags); - errno = EINTR; - return -1; - } - - do { - w = write (stream_fs->fd, buffer + written, n - written); - } while (w == -1 && errno == EINTR); - - if (w == -1) { - if (errno == EAGAIN) { - w = 0; - } else { - error = errno; + w = -1; + if (select (fdmax, &rdset, &wrset, 0, NULL) != -1) { + if (FD_ISSET (cancel_fd, &rdset)) { fcntl (stream_fs->fd, F_SETFL, flags); - errno = error; + errno = EINTR; return -1; } - } else - written += w; + + do { + w = write (stream_fs->fd, buffer + written, n - written); + } while (w == -1 && errno == EINTR); + + if (w == -1) { + if (errno == EAGAIN) { + w = 0; + } else { + error = errno; + fcntl (stream_fs->fd, F_SETFL, flags); + errno = error; + return -1; + } + } else + written += w; + } else if (errno == EINTR) { + w = 0; + } } while (w != -1 && written < n); + error = errno; fcntl (stream_fs->fd, F_SETFL, flags); + errno = error; } if (written > 0) |