#include <tchar.h>
#include "tcpsvcs.h"
+extern BOOL bShutDown;
+
DWORD WINAPI ChargenHandler(VOID* Sock_)
{
- DWORD RetVal = 0;
+ INT RetVal = 0;
SOCKET Sock = (SOCKET)Sock_;
if (!GenerateChars(Sock))
{
- _tprintf(_T("Char generation failed\n"));
- RetVal = -1;
+ LogEvent(_T("Chargen: Char generation failed\n"), 0, FALSE);
+ RetVal = 1;
}
- _tprintf(_T("Shutting connection down...\n"));
+ LogEvent(_T("Chargen: Shutting connection down...\n"), 0, FALSE);
if (ShutdownConnection(Sock, FALSE))
- _tprintf(_T("Connection is down.\n"));
+ LogEvent(_T("Chargen: Connection is down.\n"), 0, FALSE);
else
{
- _tprintf(_T("Connection shutdown failed\n"));
- RetVal = -1;
+ LogEvent(_T("Chargen: Connection shutdown failed\n"), 0, FALSE);
+ RetVal = 1;
}
- _tprintf(_T("Terminating chargen thread\n"));
+ LogEvent(_T("Chargen: Terminating thread\n"), 0, FALSE);
ExitThread(RetVal);
}
/* fill ring with printable characters */
for (charIndex=0, i=START; i<=END; charIndex++, i++)
- ring[charIndex] = i;
+ ring[charIndex] = (char)i;
/* save the address of the end character in the ring */
endring = &ring[charIndex];
/* where we will start output from */
loopIndex = 0;
- while (1)
+ while (! bShutDown)
{
/* if the loop index is equal to the last char,
* start the loop again from the beginning */
Line[LINESIZ - 2] = L'\r';
Line[LINESIZ - 1] = L'\n';
- if (!SendLine(Sock, Line))
+ if (! SendLine(Sock, Line))
break;
/* increment loop index to start printing from next char in ring */
loopIndex++;
}
-
- return TRUE;
+
+ if (bShutDown)
+ return FALSE;
+ else
+ return TRUE;
}
BOOL SendLine(SOCKET Sock, TCHAR* Line)
{
if (RetVal != LineSize)
{
- _tprintf(("Not sent enough\n"));
+ LogEvent(_T("Chargen: Not sent enough bytes\n"), 0, FALSE);
return FALSE;
}
SentBytes += RetVal;
}
else if (RetVal == SOCKET_ERROR)
{
- _tprintf(("Socket error\n"));
+ LogEvent(_T("Chargen: Socket error\n"), 0, FALSE);
return FALSE;
}
else
- _tprintf(("unknown error\n"));
- //WSAGetLastError()
+ LogEvent(_T("Chargen: unknown error\n"), 0, FALSE);
+ // return FALSE;
- _tprintf(("Connection closed by peer.\n"));
+ LogEvent(_T("Chargen: Connection closed by peer.\n"), 0, FALSE);
return TRUE;
}