diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2001-10-28 17:37:36 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2001-10-28 17:37:36 +0800 |
commit | c0cf9754b8c5ec7e13f6ee035040d792bc254ee2 (patch) | |
tree | 2de385bb6154f2a3c14ee2a07bc4a11a09a76f04 | |
parent | e79b6c7d42efa895444ee941f02fbae6c511d1ce (diff) | |
download | gsoc2013-evolution-c0cf9754b8c5ec7e13f6ee035040d792bc254ee2.tar.gz gsoc2013-evolution-c0cf9754b8c5ec7e13f6ee035040d792bc254ee2.tar.zst gsoc2013-evolution-c0cf9754b8c5ec7e13f6ee035040d792bc254ee2.zip |
Make sure we've actually read data before checking if p[-] is '\r' or not.
2001-10-28 Jeffrey Stedfast <fejj@ximian.com>
* camel-stream-buffer.c (camel_stream_buffer_read_line): Make sure
we've actually read data before checking if p[-] is '\r' or not.
svn path=/trunk/; revision=14288
-rw-r--r-- | camel/ChangeLog | 3 | ||||
-rw-r--r-- | camel/camel-stream-buffer.c | 2 | ||||
-rw-r--r-- | camel/camel-tcp-stream-raw.c | 63 |
3 files changed, 61 insertions, 7 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 8cb63ba24a..e1482db86d 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,5 +1,8 @@ 2001-10-28 Jeffrey Stedfast <fejj@ximian.com> + * camel-stream-buffer.c (camel_stream_buffer_read_line): Make sure + we've actually read data before checking if p[-] is '\r' or not. + * camel-tcp-stream-raw.c (stream_write): Same. * camel-stream-fs.c (stream_write): If errno isn't EAGAIN, just diff --git a/camel/camel-stream-buffer.c b/camel/camel-stream-buffer.c index ff7df172ae..3d7ac5e845 100644 --- a/camel/camel-stream-buffer.c +++ b/camel/camel-stream-buffer.c @@ -452,7 +452,7 @@ camel_stream_buffer_read_line (CamelStreamBuffer *sbf) } p--; - if (p[-1] == '\r') + if (p > sbf->linebuf && p[-1] == '\r') p--; p[0] = 0; diff --git a/camel/camel-tcp-stream-raw.c b/camel/camel-tcp-stream-raw.c index b5d20b61ee..3b0244ccdc 100644 --- a/camel/camel-tcp-stream-raw.c +++ b/camel/camel-tcp-stream-raw.c @@ -111,7 +111,7 @@ camel_tcp_stream_raw_get_type (void) #ifdef SIMULATE_FLAKY_NETWORK static ssize_t -tcp_write (int fd, const char *buffer, size_t buflen) +flaky_tcp_write (int fd, const char *buffer, size_t buflen) { size_t len = buflen; ssize_t nwritten; @@ -124,15 +124,15 @@ tcp_write (int fd, const char *buffer, size_t buflen) switch (val) { case 1: - printf ("tcp_write (%d, ..., %d): (-1) EINTR\n", fd, buflen); + printf ("flaky_tcp_write (%d, ..., %d): (-1) EINTR\n", fd, buflen); errno = EINTR; return -1; case 2: - printf ("tcp_write (%d, ..., %d): (-1) EAGAIN\n", fd, buflen); + printf ("flaky_tcp_write (%d, ..., %d): (-1) EAGAIN\n", fd, buflen); errno = EAGAIN; return -1; case 3: - printf ("tcp_write (%d, ..., %d): (-1) EWOULDBLOCK\n", fd, buflen); + printf ("flaky_tcp_write (%d, ..., %d): (-1) EWOULDBLOCK\n", fd, buflen); errno = EWOULDBLOCK; return -1; case 4: @@ -142,7 +142,7 @@ tcp_write (int fd, const char *buffer, size_t buflen) len = MIN (len, buflen); /* fall through... */ default: - printf ("tcp_write (%d, ..., %d): (%d) '%.*s'", fd, buflen, len, (int) len, buffer); + printf ("flaky_tcp_write (%d, ..., %d): (%d) '%.*s'", fd, buflen, len, (int) len, buffer); nwritten = write (fd, buffer, len); if (nwritten < 0) printf (" errno => %s\n", g_strerror (errno)); @@ -155,7 +155,58 @@ tcp_write (int fd, const char *buffer, size_t buflen) } } -#define write(fd, buffer, buflen) tcp_write (fd, buffer, buflen) +#define write(fd, buffer, buflen) flaky_tcp_write (fd, buffer, buflen) + +static ssize_t +flaky_tcp_read (int fd, char *buffer, size_t buflen) +{ + size_t len = buflen; + ssize_t nread; + int val; + + if (buflen == 0) + return 0; + + val = 1 + (int) (10.0 * rand () / (RAND_MAX + 1.0)); + + switch (val) { + case 1: + printf ("flaky_tcp_read (%d, ..., %d): (-1) EINTR\n", fd, buflen); + errno = EINTR; + return -1; + case 2: + printf ("flaky_tcp_read (%d, ..., %d): (-1) EAGAIN\n", fd, buflen); + errno = EAGAIN; + return -1; + case 3: + printf ("flaky_tcp_read (%d, ..., %d): (-1) EWOULDBLOCK\n", fd, buflen); + errno = EWOULDBLOCK; + return -1; + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + len = 1 + (size_t) (10.0 * rand () / (RAND_MAX + 1.0)); + len = MIN (len, buflen); + /* fall through... */ + default: + printf ("flaky_tcp_read (%d, ..., %d): (%d)", fd, buflen, len); + nread = read (fd, buffer, len); + if (nread < 0) + printf (" errno => %s\n", g_strerror (errno)); + else if (nread < len) + printf (" only read %d bytes\n", nread); + else + printf ("\n"); + + return nread; + } +} + +#define read(fd, buffer, buflen) flaky_tcp_read (fd, buffer, buflen) #endif /* SIMULATE_FLAKY_NETWORK */ |