From 7a226bb8f5a070842eed562c04df6b79970a4e4b Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Sun, 6 Jun 2010 21:12:11 +0200 Subject: [PATCH] handle SIGPIPE --- rigold.c | 19 +++++++++++++++++++ usbtmc.c | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/rigold.c b/rigold.c index 974a814..8f73431 100644 --- a/rigold.c +++ b/rigold.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "scope.h" #include "commands.h" @@ -115,8 +116,14 @@ static void parse_request(int s, struct scope *sc) } } +void sighandler(int sig) +{ + printf("Signal %d received\n", sig); +} + int main(int argc, char **argv) { + struct sigaction act; int sock, csock; int opt; socklen_t slen; @@ -125,6 +132,18 @@ int main(int argc, char **argv) unsigned short port = 8088; sc = initscope(); + if (sc == NULL) { + printf("Scope not found!\n"); + exit(EXIT_FAILURE); + } + + bzero(&act, sizeof(act)); + act.sa_handler = sighandler; + act.sa_flags = SA_RESTART; + if (sigaction(SIGPIPE, &act, NULL) == -1) { + perror("sigaction"); + exit(EXIT_FAILURE); + } if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); diff --git a/usbtmc.c b/usbtmc.c index 0249e25..729f6db 100644 --- a/usbtmc.c +++ b/usbtmc.c @@ -6,7 +6,7 @@ #include "usbtmc.h" -#define USB_TIMEOUT 10000 +#define USB_TIMEOUT 50000 //Helper-routine: Convert a little-endian 4-byte word to an int static void int2chars(unsigned char *buff,unsigned int a) { -- 2.39.5