From owner-freebsd-hackers Thu May 7 20:18:58 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id UAA06532 for freebsd-hackers-outgoing; Thu, 7 May 1998 20:18:58 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from huey.cadvision.com (huey.cadvision.com [207.228.64.47]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id UAA06460 for ; Thu, 7 May 1998 20:18:29 -0700 (PDT) (envelope-from kielyd@cadvision.com) Received: from zimbra (ts59ip102.cadvision.com [207.228.74.102]) by huey.cadvision.com (8.8.8/8.8.8/CW) with SMTP id VAA1263712 for ; Thu, 7 May 1998 21:18:25 -0600 Received: by localhost with Microsoft MAPI; Thu, 7 May 1998 21:15:51 -0600 Message-ID: <01BD79FD.50151E50.kielyd@cadvision.com> From: Daryn Kiely To: "'freebsd-hackers@FreeBSD.ORG'" Subject: Coding question Date: Thu, 7 May 1998 21:15:43 -0600 X-Mailer: Microsoft Internet E-mail/MAPI - 8.0.0.4211 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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