aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-stream-fs.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2001-01-15 15:55:30 +0800
committerMichael Zucci <zucchi@src.gnome.org>2001-01-15 15:55:30 +0800
commitb64ffc9183d2c94ce6b8fdf10f382904aa8021e8 (patch)
tree701629078be7b75865fe87c9a348e2d5361004c6 /camel/camel-stream-fs.c
parentcff9059380f748309b628041b55abad159aab4d6 (diff)
downloadgsoc2013-evolution-b64ffc9183d2c94ce6b8fdf10f382904aa8021e8.tar
gsoc2013-evolution-b64ffc9183d2c94ce6b8fdf10f382904aa8021e8.tar.gz
gsoc2013-evolution-b64ffc9183d2c94ce6b8fdf10f382904aa8021e8.tar.bz2
gsoc2013-evolution-b64ffc9183d2c94ce6b8fdf10f382904aa8021e8.tar.lz
gsoc2013-evolution-b64ffc9183d2c94ce6b8fdf10f382904aa8021e8.tar.xz
gsoc2013-evolution-b64ffc9183d2c94ce6b8fdf10f382904aa8021e8.tar.zst
gsoc2013-evolution-b64ffc9183d2c94ce6b8fdf10f382904aa8021e8.zip
A cancellable connection routine. (remote_send_string): Return cancelled
2001-01-15 Not Zed <NotZed@Ximian.com> * camel-remote-store.c (socket_connect): A cancellable connection routine. (remote_send_string): Return cancelled exception if we were. (remote_send_stream): " (remote_recv_line): " * camel-stream-fs.c (stream_read): First cut at cancellation stuff. Its looking a bit ugly. svn path=/trunk/; revision=7496
Diffstat (limited to 'camel/camel-stream-fs.c')
-rw-r--r--camel/camel-stream-fs.c69
1 files changed, 62 insertions, 7 deletions
diff --git a/camel/camel-stream-fs.c b/camel/camel-stream-fs.c
index 59082ec531..9f05b2fd8c 100644
--- a/camel/camel-stream-fs.c
+++ b/camel/camel-stream-fs.c
@@ -209,13 +209,39 @@ stream_read (CamelStream *stream, char *buffer, size_t n)
CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
ssize_t nread;
+ int cancel_fd;
+
+ if (camel_cancel_check(NULL)) {
+ errno = EINTR;
+ return -1;
+ }
if (seekable->bound_end != CAMEL_STREAM_UNBOUND)
n = MIN (seekable->bound_end - seekable->position, n);
- do {
- nread = read (stream_fs->fd, buffer, n);
- } while (nread == -1 && errno == EINTR);
+ cancel_fd = camel_cancel_fd(NULL);
+ if (cancel_fd == -1) {
+ do {
+ nread = read (stream_fs->fd, buffer, n);
+ } while (nread == -1 && errno == EINTR);
+ } else {
+ fd_set rdset;
+ long flags;
+
+ fcntl(stream_fs->fd, F_GETFL, &flags);
+ fcntl(stream_fs->fd, F_SETFL, flags | O_NONBLOCK);
+ FD_ZERO(&rdset);
+ FD_SET(stream_fs->fd, &rdset);
+ FD_SET(cancel_fd, &rdset);
+ select((stream_fs->fd+cancel_fd)/2+1, &rdset, 0, 0, NULL);
+ if (FD_ISSET(cancel_fd, &rdset)) {
+ fcntl(stream_fs->fd, F_SETFL, flags);
+ errno = EINTR;
+ return -1;
+ }
+ nread = read(stream_fs->fd, buffer, n);
+ fcntl(stream_fs->fd, F_SETFL, flags);
+ }
if (nread > 0)
seekable->position += nread;
@@ -231,15 +257,44 @@ stream_write (CamelStream *stream, const char *buffer, size_t n)
CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
ssize_t v, written = 0;
+ int cancel_fd;
+
+ if (camel_cancel_check(NULL)) {
+ errno = EINTR;
+ return -1;
+ }
if (seekable->bound_end != CAMEL_STREAM_UNBOUND)
n = MIN (seekable->bound_end - seekable->position, n);
- do {
- v = write (stream_fs->fd, buffer, n);
- if (v > 0)
+ cancel_fd = camel_cancel_fd(NULL);
+ if (cancel_fd == -1) {
+ do {
+ v = write (stream_fs->fd, buffer, n);
+ if (v > 0)
+ written += v;
+ } while (v == -1 && errno == EINTR);
+ } else {
+ fd_set rdset, wrset;
+ long flags;
+
+ fcntl(stream_fs->fd, F_GETFL, &flags);
+ fcntl(stream_fs->fd, F_SETFL, flags | O_NONBLOCK);
+ FD_ZERO(&rdset);
+ FD_ZERO(&wrset);
+ FD_SET(stream_fs->fd, &wrset);
+ FD_SET(cancel_fd, &rdset);
+ select((stream_fs->fd+cancel_fd)/2+1, &rdset, &wrset, 0, NULL);
+ if (FD_ISSET(cancel_fd, &rdset)) {
+ fcntl(stream_fs->fd, F_SETFL, flags);
+ errno = EINTR;
+ return -1;
+ }
+ v = write(stream_fs->fd, buffer, n);
+ if (v>0)
written += v;
- } while (v == -1 && errno == EINTR);
+ fcntl(stream_fs->fd, F_SETFL, flags);
+ }
if (written > 0)
seekable->position += written;