diff -r 69f8c0acaac7 -r 675be0a45157 render_node.c --- a/render_node.c Sat May 31 19:35:21 2008 +0300 +++ b/render_node.c Sun Jun 01 01:48:09 2008 +0300 @@ -3,12 +3,29 @@ #include #include #include +#include +#include #include "render.h" #include "render_remote.h" #include "mandelbrot.h" #include "common.h" +void sigpipe_handler (int signal) { + /* ignore */ + fprintf(stderr, "SIGPIPE\n"); +} + +void sigpipe_ignore () { + struct sigaction sigpipe_action; + + memset(&sigpipe_action, 0, sizeof(sigpipe_action)); + sigpipe_action.sa_handler = SIG_IGN; + + if (sigaction(SIGPIPE, &sigpipe_action, NULL)) + perr_exit("sigaction"); +} + int my_fread(FILE *fh, void *ptr, size_t size) { int ret = fread(ptr, size, 1, fh); @@ -78,10 +95,13 @@ render_region_raw(&ctx, x1, y1, x2, y2); render_io_stream(&ctx, fh); + sigpipe_ignore(); + // render! - mandelbrot_render_timed(&ctx, &duration); - - printf("time=%fs\n", duration); + if (mandelbrot_render_timed(&ctx, &duration)) + printf("error\n"); // XXX: notify our client? + else + printf("time=%fs\n", duration); // close the FILE* and socket fclose(fh); @@ -89,14 +109,16 @@ return; } + int main (int argc, char** argv) { int ssock, sock; struct sockaddr_in addr; socklen_t addr_len; + // create the socket if ((ssock = socket(PF_INET, SOCK_STREAM, 0)) == -1) - die("socket"); + perr_exit("socket"); addr.sin_family = AF_INET; addr.sin_port = htons(RENDER_PORT); @@ -106,10 +128,10 @@ addr.sin_port = htons(atoi(argv[1])); if (bind(ssock, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) == -1) - die("bind"); + perr_exit("bind"); if (listen(ssock, 1) == -1) - die("listen"); + perr_exit("listen"); printf("RUN: %s:%hu\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); @@ -119,7 +141,7 @@ // accept a new client if ((sock = accept(ssock, (struct sockaddr *) &addr, &addr_len)) == -1) - die("accept"); + perr_exit("accept"); printf("ACCEPT: %s:%hu\n", inet_ntoa(addr.sin_addr), addr.sin_port);