From 21d75884427965eca52fc393f142f0c7f463e616 Mon Sep 17 00:00:00 2001 From: dcp1990 Date: Mon, 13 Jun 2005 22:16:09 +0000 Subject: [PATCH] Check if socket is dead so we don't get that darn SIGPIPE --- phoned/remote.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/phoned/remote.c b/phoned/remote.c index 14e63b6..dff9a19 100644 --- a/phoned/remote.c +++ b/phoned/remote.c @@ -28,13 +28,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* $Amigan: phoned/phoned/remote.c,v 1.3 2005/06/13 22:02:27 dcp1990 Exp $ */ +/* $Amigan: phoned/phoned/remote.c,v 1.4 2005/06/13 22:16:09 dcp1990 Exp $ */ /* system includes */ #include #include #include #include #include +#include /* us */ #include #define MAXBUFSIZE 512 @@ -107,17 +108,28 @@ void begin_dialogue(fp, fd) char buffer[MAXBUFSIZE]; /* molto importante */ char *rcode, *c; short keep_going = 0x1; + int rc = 0; state_info_t si; memset(&si, 0, sizeof(state_info_t)); si.fpo = fp; /* this is JUST for data, not real commands */ si.fd = fd; while(keep_going == 0x1 && !feof(fp)) { - if(recv(fd, buffer, MAXBUFSIZE - 1, 0x0) == -1) break; + rc = recv(fd, buffer, MAXBUFSIZE - 1, 0x0); + if(rc == 0) { + lprintf(debug, "Socket closed! Got zero!\n"); + break; + } else if(rc == -1) { + lprintf(error, "Error with recv: %s\n", strerror(errno)); + break; + } if((c = strrchr(buffer, '\n')) != NULL) *c = '\0'; rcode = parse_command(buffer, &keep_going, &si); if(rcode != NULL) { - send(fd, rcode, strlen(rcode) + 1, 0); + if(send(fd, rcode, strlen(rcode) + 1, 0) == 0x0) { + lprintf(error, "Error: (send() inside begin_dialogue()): %s\n", strerror(errno)); + break; + } if(si.freeit) free(rcode); } }