Date: Sat, 9 May 1998 01:16:30 -0400 (EDT) From: Dan Janowski <danj@3skel.com> To: Daryn Kiely <kielyd@cadvision.com> Cc: "'freebsd-hackers@FreeBSD.ORG'" <freebsd-hackers@FreeBSD.ORG> Subject: Re: Coding question Message-ID: <Pine.BSF.3.95q.980509011104.26008B-100000@fnur.3skel.com> In-Reply-To: <01BD79FD.50151E50.kielyd@cadvision.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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,"<send_mdt_message> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.95q.980509011104.26008B-100000>
