Date: Thu, 7 May 1998 21:15:43 -0600 From: Daryn Kiely <kielyd@cadvision.com> To: "'freebsd-hackers@FreeBSD.ORG'" <freebsd-hackers@FreeBSD.ORG> Subject: Coding question Message-ID: <01BD79FD.50151E50.kielyd@cadvision.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01BD79FD.50151E50.kielyd>
