diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-09-25 00:16:45 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-09-26 13:42:28 +0100 |
commit | f2c484d73ce61012a2d9925f15b55e7c51e34b85 (patch) | |
tree | c5278fc614cfd707e5a2c3f0b85711b7af65985c /test/any2ppm.c | |
parent | 681424cbaf94556bf1804547b42ad642c0a066ab (diff) | |
download | cairo-f2c484d73ce61012a2d9925f15b55e7c51e34b85.tar.gz |
[test/any2ppm] Handle short reads/writes.
No excuse other than simple laziness - it manifested itself with random
"error whilst reading" failures.
Diffstat (limited to 'test/any2ppm.c')
-rw-r--r-- | test/any2ppm.c | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/test/any2ppm.c b/test/any2ppm.c index bca35f3cd..412bbb8bc 100644 --- a/test/any2ppm.c +++ b/test/any2ppm.c @@ -79,6 +79,7 @@ #include <sys/socket.h> #include <sys/poll.h> #include <sys/un.h> +#include <errno.h> #define SOCKET_PATH "./.any2ppm" #define TIMEOUT 60000 /* 60 seconds */ @@ -89,6 +90,30 @@ #define ARRAY_LENGTH(A) (sizeof (A) / sizeof (A[0])) static int +_writen (int fd, char *buf, int len) +{ + while (len) { + int ret; + + ret = write (fd, buf, len); + if (ret == -1) { + int err = errno; + switch (err) { + case EINTR: + case EAGAIN: + continue; + default: + return 0; + } + } + len -= ret; + buf += ret; + } + + return 1; +} + +static int _write (int fd, char *buf, int maxlen, int buflen, const unsigned char *src, int srclen) @@ -110,8 +135,9 @@ _write (int fd, src += len; if (buflen == maxlen) { - if (write (fd, buf, maxlen) != maxlen) + if (! _writen (fd, buf, buflen)) return -1; + buflen = 0; } } @@ -180,10 +206,8 @@ write_ppm (cairo_surface_t *surface, int fd) return "write failed"; } - if (len) { - if (write (fd, buf, len) != len) - return "write failed"; - } + if (len && ! _writen (fd, buf, len)) + return "write failed"; return NULL; } @@ -548,8 +572,20 @@ any2ppm_daemon (void) if (_getline (fd, &line, &len) != -1) { char *argv[10]; - if (split_line (line, argv, ARRAY_LENGTH (argv)) > 0) - convert (argv, fd); + if (split_line (line, argv, ARRAY_LENGTH (argv)) > 0) { + const char *err; + + err = convert (argv, fd); + if (err != NULL) { + FILE *file = fopen (".any2ppm.errors", "a"); + if (file != NULL) { + fprintf (file, + "Failed to convert '%s': %s\n", + argv[0], err); + fclose (file); + } + } + } } close (fd); } |