#include <stdio.h>
#include <fcntl.h>
#include <time.h>
+#include <signal.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
int ct = -1;
fd_set fds;
struct timeval timeout, before, after;
+ struct sigaction sa,osa;
+ memset(&sa,0,sizeof(sa)); assert(sa.sa_handler == NULL);
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGPIPE,&sa,&osa);
if ( to ) {
memcpy(&timeout, to, sizeof(timeout));
if (to->tv_sec < 0) to->tv_sec = to->tv_usec = 0;
}
+ sigaction(SIGPIPE,&osa,NULL);
+ if (errno == EPIPE) errno = ENOTCONN;
return (errno)? -1: written;
}