From owner-freebsd-hackers Fri May 8 22:16:48 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id WAA25007 for freebsd-hackers-outgoing; Fri, 8 May 1998 22:16:48 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from aaka.3skel.com (aaka.3skel.com [207.240.212.3]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id WAA24958 for ; Fri, 8 May 1998 22:16:35 -0700 (PDT) (envelope-from danj@3skel.com) Received: from fnur.3skel.com (fnur.3skel.com [192.168.0.8]) by aaka.3skel.com (8.8.5/8.8.2) with ESMTP id BAA05720; Sat, 9 May 1998 01:16:30 -0400 (EDT) Received: from localhost (danj@localhost) by fnur.3skel.com (8.8.5/8.8.2) with SMTP id BAA26037; Sat, 9 May 1998 01:16:30 -0400 (EDT) Date: Sat, 9 May 1998 01:16:30 -0400 (EDT) From: Dan Janowski To: Daryn Kiely cc: "'freebsd-hackers@FreeBSD.ORG'" Subject: Re: Coding question In-Reply-To: <01BD79FD.50151E50.kielyd@cadvision.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Brain rusty, didn't read your code, read uipc_socket.c: It seems that a write to a socket with the remote end closed will generate a SIGPIPE. Did you run this thing with gdb? It will tell you about signals that your program doesn't catch. Dan On Thu, 7 May 1998, Daryn Kiely wrote: > Hi there, > > I am currently working on a sockets program (using TCP connections) which > has both a client and server. I am finding that when the server closes the > connection and a client attempts to do a write() the program is exiting > (never returns from the write). Now I was actually expecting the client > process to receive a -1 when attempting to write to a closed socket. Has > anyone else experienced this problem, or does anyone have any suggestions > as to how I can get around it? > > TIA > Daryn > > > ----------------- Code snippets -------------------------- > > void RunProcess() > > { > int fdServer, iNumChars, iStatus, iLength; > char temp[1000], *pOutput; > int iReturnValue; > > signal(SIGINT,SignalHandler); > > while (!g_iDone) { > /* must read the server name and socket name from config file */ > fdServer = ConnectToServer("daryn","smtp"); > if (fdServer < 0) { /* Failed to connect to the server */ > LogPrintf(SEV_FAIL," Failed > connecting to server [%d]\n",errno); > sleep(10); > /* Make this sleep configurable */ > continue; > } > g_iConnected = 1; > > while (g_iConnected && !g_iDone) { > iNumChars = ReadFromSocket(fdServer,temp,1000, 10); > temp[iNumChars] = '\0'; > LogPrintf(SEV_DEBUG,"%s\n",temp); > pOutput = BuildPacket(&iLength); > if (WriteToSocket(fdServer,pOutput,iLength) != > iLength) { > LogPrintf(SEV_WARN,"Failed writing to > socket, attempting to reconnect [%d]\n",errno); > g_iConnected = 0; > } > } > CloseSocket(fdServer); > } > } > > size_t WriteToSocket(int fdSocket, const void *buffer, size_t iLength) > > { > int iReturnValue; > fprintf(stderr,"5.0\n"); > iReturnValue = write(fdSocket, buffer,iLength); > fprintf(stderr,"5.1, return value = [%d]\n", iReturnValue); > return(iReturnValue); > } > > I see the 5.0 line of output but never see the "5.1". > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > -- danj@3skel.com Dan Janowski Triskelion Systems, Inc. Bronx, NY To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message