[Larceny-users] Larceny Runtime - SIGPIPE Handled?

Chris Brannon cmbrannon at cox.net
Mon May 19 00:18:15 EDT 2008


Ray Racine <ray.racine at comcast.net> writes:

> My theory is, when the client is interrupted the socket is closed. The
> Larceny server continues to try writing to the socket fd resulting in
> the SIGPIPE signal and causing the exit.  I looked briefly at signals.c
> and don't see it being handled or masked.  But I didn't look very
> hard :).

Are you checking the return value of write(2), to make sure that you don't
do a partially successful write?  Most people only check for a negative
return value, assuming that they check at all.  If your write(2) call
doesn't write all the data that you supplied, then you had a partial write,
and it's probably safe to assume that the connection was closed at the
other end.
Here's an example, in C.

while(1) {
  char *msg = get_next_datum(); /* Get something to write. */
  int msg_length = strlen(msg);
  int num_written = write(some_socket, msg, msg_length);
  if(num_written != msg_length) {
    printf("Error sending data.\n");
    /* Do whatever is necessary to handle error. */
  }
}

In other words, I think you can avoid sigpipe by simply checking the
return value of write(2).  Someone correct me if I'm wrong.

-- Chris



More information about the Larceny-users mailing list