diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2003-07-09 01:48:32 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2003-07-09 01:48:32 +0800 |
commit | a58c26d7a588f6822469072b68aa38319175f588 (patch) | |
tree | f8ee0cfb81e509596620ddc4e68cf5f1415ea560 | |
parent | abb46e8ee1327909e2fafc080298319b8edbc9ff (diff) | |
download | gsoc2013-evolution-a58c26d7a588f6822469072b68aa38319175f588.tar.gz gsoc2013-evolution-a58c26d7a588f6822469072b68aa38319175f588.tar.zst gsoc2013-evolution-a58c26d7a588f6822469072b68aa38319175f588.zip |
Use camel_read(). (stream_write): Use camel_write().
2003-07-08 Jeffrey Stedfast <fejj@ximian.com>
* camel-tcp-stream-raw.c (stream_read): Use camel_read().
(stream_write): Use camel_write().
* camel-stream-fs.c (stream_read): Use camel_read().
(stream_write): Use camel_write().
svn path=/trunk/; revision=21758
-rw-r--r-- | camel/ChangeLog | 8 | ||||
-rw-r--r-- | camel/camel-stream-fs.c | 127 | ||||
-rw-r--r-- | camel/camel-tcp-stream-raw.c | 124 |
3 files changed, 18 insertions, 241 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 36cc6a5272..456ac014ad 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,11 @@ +2003-07-08 Jeffrey Stedfast <fejj@ximian.com> + + * camel-tcp-stream-raw.c (stream_read): Use camel_read(). + (stream_write): Use camel_write(). + + * camel-stream-fs.c (stream_read): Use camel_read(). + (stream_write): Use camel_write(). + 2003-07-07 Jeffrey Stedfast <fejj@ximian.com> * providers/nntp/camel-nntp-folder.c (camel_nntp_folder_new): Use diff --git a/camel/camel-stream-fs.c b/camel/camel-stream-fs.c index 917fd1f8e1..501f704b6d 100644 --- a/camel/camel-stream-fs.c +++ b/camel/camel-stream-fs.c @@ -5,7 +5,7 @@ * Authors: Bertrand Guiheneuf <bertrand@helixcode.com> * Michael Zucchi <notzed@ximian.com> * - * Copyright 1999, 2000 Ximian, Inc. (www.ximian.com) + * Copyright 1999-2003 Ximian, Inc. (www.ximian.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -33,6 +33,7 @@ #include <errno.h> #include <string.h> +#include "camel-file-utils.h" #include "camel-operation.h" #include "camel-stream-fs.h" #include "camel-session.h" @@ -214,62 +215,11 @@ 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_operation_cancel_check(NULL)) { - errno = EINTR; - return -1; - } if (seekable->bound_end != CAMEL_STREAM_UNBOUND) n = MIN (seekable->bound_end - seekable->position, n); - cancel_fd = camel_operation_cancel_fd(NULL); - if (cancel_fd == -1) { - do { - nread = read (stream_fs->fd, buffer, n); - } while (nread == -1 && (errno == EINTR || errno == EAGAIN)); - } else { - fd_set rdset; - int error, flags, fdmax; - - flags = fcntl (stream_fs->fd, F_GETFL); - fcntl (stream_fs->fd, F_SETFL, flags | O_NONBLOCK); - - do { - FD_ZERO (&rdset); - FD_SET (stream_fs->fd, &rdset); - FD_SET (cancel_fd, &rdset); - fdmax = MAX (stream_fs->fd, cancel_fd) + 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; - } - } while (nread == -1 && errno == EAGAIN); - - error = errno; - fcntl (stream_fs->fd, F_SETFL, flags); - errno = error; - } - - if (nread > 0) - seekable->position += nread; - else if (nread == 0) - stream->eos = TRUE; - - return nread; + return camel_read (stream_fs->fd, buffer, n); } static ssize_t @@ -277,80 +227,11 @@ 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 w, written = 0; - int cancel_fd; - - if (camel_operation_cancel_check(NULL)) { - errno = EINTR; - return -1; - } if (seekable->bound_end != CAMEL_STREAM_UNBOUND) n = MIN (seekable->bound_end - seekable->position, n); - cancel_fd = camel_operation_cancel_fd(NULL); - if (cancel_fd == -1) { - do { - do { - w = write (stream_fs->fd, buffer + written, n - written); - } while (w == -1 && (errno == EINTR || errno == EAGAIN)); - - if (w > 0) - written += w; - } while (w != -1 && written < n); - } else { - fd_set rdset, wrset; - int error, flags, fdmax; - - flags = fcntl (stream_fs->fd, F_GETFL); - fcntl (stream_fs->fd, F_SETFL, flags | O_NONBLOCK); - - fdmax = MAX (stream_fs->fd, cancel_fd)+1; - do { - FD_ZERO (&rdset); - FD_ZERO (&wrset); - FD_SET (stream_fs->fd, &wrset); - FD_SET (cancel_fd, &rdset); - - w = -1; - if (select (fdmax, &rdset, &wrset, 0, NULL) != -1) { - 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; - 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) - seekable->position += written; - else if (w == -1) - return -1; - - return written; + return camel_write (stream_fs->fd, buffer, n); } static int diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c index cf6a1f539d..819647cff6 100644 --- a/camel/camel-tcp-stream-raw.c +++ b/camel/camel-tcp-stream-raw.c @@ -2,7 +2,7 @@ /* * Authors: Jeffrey Stedfast <fejj@ximian.com> * - * Copyright 2001 Ximian, Inc. (www.ximian.com) + * Copyright 2001-2003 Ximian, Inc. (www.ximian.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -35,6 +35,7 @@ #include <errno.h> #include "camel-tcp-stream-raw.h" +#include "camel-file-utils.h" #include "camel-operation.h" static CamelTcpStreamClass *parent_class = NULL; @@ -234,130 +235,17 @@ camel_tcp_stream_raw_new () static ssize_t stream_read (CamelStream *stream, char *buffer, size_t n) { - CamelTcpStreamRaw *tcp_stream_raw = CAMEL_TCP_STREAM_RAW (stream); - ssize_t nread; - int cancel_fd; - - if (camel_operation_cancel_check (NULL)) { - errno = EINTR; - return -1; - } - - cancel_fd = camel_operation_cancel_fd (NULL); - if (cancel_fd == -1) { - do { - nread = read (tcp_stream_raw->sockfd, buffer, n); - } while (nread == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)); - } else { - int error, flags, fdmax; - fd_set rdset; - - flags = fcntl (tcp_stream_raw->sockfd, F_GETFL); - fcntl (tcp_stream_raw->sockfd, F_SETFL, flags | O_NONBLOCK); - - do { - FD_ZERO (&rdset); - FD_SET (tcp_stream_raw->sockfd, &rdset); - FD_SET (cancel_fd, &rdset); - fdmax = MAX (tcp_stream_raw->sockfd, cancel_fd) + 1; - - nread = -1; - if (select (fdmax, &rdset, 0, 0, NULL) != -1) { - if (FD_ISSET (cancel_fd, &rdset)) { - fcntl (tcp_stream_raw->sockfd, F_SETFL, flags); - errno = EINTR; - return -1; - } - - do { - nread = read (tcp_stream_raw->sockfd, buffer, n); - } while (nread == -1 && errno == EINTR); - } else if (errno == EINTR) { - errno = EAGAIN; - } - } while (nread == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)); - - error = errno; - fcntl (tcp_stream_raw->sockfd, F_SETFL, flags); - errno = error; - } + CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream); - return nread; + return camel_read (raw->sockfd, buffer, n); } static ssize_t stream_write (CamelStream *stream, const char *buffer, size_t n) { - CamelTcpStreamRaw *tcp_stream_raw = CAMEL_TCP_STREAM_RAW (stream); - ssize_t w, written = 0; - int cancel_fd; - - if (camel_operation_cancel_check (NULL)) { - errno = EINTR; - return -1; - } - - cancel_fd = camel_operation_cancel_fd (NULL); - if (cancel_fd == -1) { - do { - do { - w = write (tcp_stream_raw->sockfd, buffer + written, n - written); - } while (w == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)); - - if (w > 0) - written += w; - } while (w != -1 && written < n); - } else { - int error, flags, fdmax; - fd_set rdset, wrset; - - flags = fcntl (tcp_stream_raw->sockfd, F_GETFL); - fcntl (tcp_stream_raw->sockfd, F_SETFL, flags | O_NONBLOCK); - - fdmax = MAX (tcp_stream_raw->sockfd, cancel_fd) + 1; - do { - FD_ZERO (&rdset); - FD_ZERO (&wrset); - FD_SET (tcp_stream_raw->sockfd, &wrset); - FD_SET (cancel_fd, &rdset); - - w = -1; - if (select (fdmax, &rdset, &wrset, 0, NULL) != -1) { - if (FD_ISSET (cancel_fd, &rdset)) { - fcntl (tcp_stream_raw->sockfd, F_SETFL, flags); - errno = EINTR; - return -1; - } - - do { - w = write (tcp_stream_raw->sockfd, buffer + written, n - written); - } while (w == -1 && errno == EINTR); - - if (w == -1) { - if (errno == EAGAIN || errno == EWOULDBLOCK) { - w = 0; - } else { - error = errno; - fcntl (tcp_stream_raw->sockfd, F_SETFL, flags); - errno = error; - return -1; - } - } else - written += w; - } else if (errno == EINTR) { - w = 0; - } - } while (w != -1 && written < n); - - error = errno; - fcntl (tcp_stream_raw->sockfd, F_SETFL, flags); - errno = error; - } - - if (w == -1) - return -1; + CamelTcpStreamRaw *raw = CAMEL_TCP_STREAM_RAW (stream); - return written; + return camel_write (raw->sockfd, buffer, n); } static int |