[broadway] Track errors in BroadwayOutput

This commit is contained in:
Alexander Larsson 2010-11-24 22:12:29 +01:00
parent ce5cccf0ab
commit 0ca5a1a574
2 changed files with 30 additions and 10 deletions

View File

@ -449,7 +449,8 @@ to_png_a (int w, int h, int byte_stride, guint8 *data)
struct BroadwayOutput { struct BroadwayOutput {
int fd; int fd;
gzFile *zfd; gzFile *zfd;
} ; int error;
};
static void static void
broadway_output_write_raw (BroadwayOutput *output, broadway_output_write_raw (BroadwayOutput *output,
@ -459,6 +460,9 @@ broadway_output_write_raw (BroadwayOutput *output,
int errsave; int errsave;
const char *ptr = (const char *)buf; const char *ptr = (const char *)buf;
if (output->error)
return;
while (count > 0) while (count > 0)
{ {
res = write(output->fd, ptr, count); res = write(output->fd, ptr, count);
@ -467,13 +471,13 @@ broadway_output_write_raw (BroadwayOutput *output,
errsave = errno; errsave = errno;
if (errsave == EINTR) if (errsave == EINTR)
continue; continue;
fprintf(stderr, "Error on write_raw to output %d\n", errsave); output->error = TRUE;
exit(1); return;
} }
if (res == 0) if (res == 0)
{ {
fprintf(stderr, "Short write_raw to output\n"); output->error = TRUE;
exit(1); return;
} }
count -= res; count -= res;
ptr += res; ptr += res;
@ -487,18 +491,21 @@ broadway_output_write (BroadwayOutput *output,
gssize res; gssize res;
const char *ptr = (const char *)buf; const char *ptr = (const char *)buf;
if (output->error)
return;
while (count > 0) while (count > 0)
{ {
res = gzwrite(output->zfd, ptr, count); res = gzwrite(output->zfd, ptr, count);
if (res == -1) if (res == -1)
{ {
fprintf(stderr, "Error on write to output\n"); output->error = TRUE;
exit(1); return;
} }
if (res == 0) if (res == 0)
{ {
fprintf(stderr, "Short write to output\n"); output->error = TRUE;
exit(1); return;
} }
count -= res; count -= res;
ptr += res; ptr += res;
@ -549,10 +556,21 @@ broadway_output_new(int fd)
} }
void void
broadway_output_free (BroadwayOutput *output)
{
if (output->zfd)
gzclose (output->zfd);
else
close (output->fd);
free (output);
}
int
broadway_output_flush (BroadwayOutput *output) broadway_output_flush (BroadwayOutput *output)
{ {
send_boundary (output); send_boundary (output);
gzflush (output->zfd, Z_SYNC_FLUSH); gzflush (output->zfd, Z_SYNC_FLUSH);
return !output->error;
} }

View File

@ -6,7 +6,9 @@ typedef struct {
} BroadwayRect; } BroadwayRect;
BroadwayOutput *broadway_output_new (int fd); BroadwayOutput *broadway_output_new (int fd);
void broadway_output_flush (BroadwayOutput *output); void broadway_output_free (BroadwayOutput *output);
int broadway_output_flush (BroadwayOutput *output);
int broadway_output_has_error (BroadwayOutput *output);
void broadway_output_new_surface (BroadwayOutput *output, void broadway_output_new_surface (BroadwayOutput *output,
int id, int id,
int x, int x,