aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-tcp-stream-raw.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-10-28 17:37:36 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-10-28 17:37:36 +0800
commitc0cf9754b8c5ec7e13f6ee035040d792bc254ee2 (patch)
tree2de385bb6154f2a3c14ee2a07bc4a11a09a76f04 /camel/camel-tcp-stream-raw.c
parente79b6c7d42efa895444ee941f02fbae6c511d1ce (diff)
downloadgsoc2013-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
Diffstat (limited to 'camel/camel-tcp-stream-raw.c')
-rw-r--r--camel/camel-tcp-stream-raw.c63
1 files changed, 57 insertions, 6 deletions
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 */