diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-05-03 09:16:17 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-05-03 09:16:17 +0800 |
commit | dd2a60f012698179a4766441cfb40ce5b13c1eaa (patch) | |
tree | 2c0ae2f163120d9a99cef510ba5341aaf17d71ae /camel/camel-stream-fs.c | |
parent | b3a906a2eca869ccd2dcd4a067aa60ede5b25ddb (diff) | |
download | gsoc2013-evolution-dd2a60f012698179a4766441cfb40ce5b13c1eaa.tar.gz gsoc2013-evolution-dd2a60f012698179a4766441cfb40ce5b13c1eaa.tar.zst gsoc2013-evolution-dd2a60f012698179a4766441cfb40ce5b13c1eaa.zip |
Same fix as the tcp stream. (stream_write): Again here. Just like tcp
2002-05-02 Jeffrey Stedfast <fejj@ximian.com>
* camel-stream-fs.c (stream_read): Same fix as the tcp stream.
(stream_write): Again here. Just like tcp stream's stream_write(),
also make sure to save errno before calling fcntl to restore the
fd flags.
* camel-tcp-stream-raw.c (stream_read): Handle EINTR errors for
select().
(stream_write): Same and also preserve errno when setting the fd
flags back. If w == -1, return -1.
svn path=/trunk/; revision=16673
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) |