2006-11-08 11:47:44 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS simple TCP/IP services
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2015-09-12 10:58:07 +00:00
|
|
|
* FILE: base/services/tcpsvcs/discard.c
|
2013-04-13 21:28:10 +00:00
|
|
|
* PURPOSE: Receives input from a client and discards it
|
2008-04-02 16:54:55 +00:00
|
|
|
* COPYRIGHT: Copyright 2005 - 2008 Ged Murphy <gedmurphy@reactos.org>
|
2006-11-08 11:47:44 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tcpsvcs.h"
|
|
|
|
|
2008-04-02 16:54:55 +00:00
|
|
|
#define BUFSIZE 1024
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2008-04-02 16:54:55 +00:00
|
|
|
static BOOL
|
2013-04-13 21:28:10 +00:00
|
|
|
ReceiveIncomingPackets(SOCKET sock)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2008-09-01 12:51:49 +00:00
|
|
|
CHAR readBuffer[BUFSIZE];
|
2008-04-02 16:54:55 +00:00
|
|
|
INT readBytes;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2008-04-02 16:54:55 +00:00
|
|
|
readBytes = recv(sock, readBuffer, BUFSIZE, 0);
|
|
|
|
if (readBytes > 0)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2008-04-02 16:54:55 +00:00
|
|
|
TCHAR logBuf[256];
|
|
|
|
|
2014-05-26 14:03:24 +00:00
|
|
|
swprintf(logBuf, L"Discard: Received %d bytes from client", readBytes);
|
2008-04-02 16:54:55 +00:00
|
|
|
LogEvent(logBuf, 0, 0, LOG_FILE);
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
2008-04-02 16:54:55 +00:00
|
|
|
else if (readBytes == SOCKET_ERROR)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"Discard: Socket Error", WSAGetLastError(), 0, LOG_ERROR);
|
2006-11-08 11:47:44 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2008-04-02 16:54:55 +00:00
|
|
|
} while ((readBytes > 0) && (!bShutdown));
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2008-04-02 16:54:55 +00:00
|
|
|
if (!bShutdown)
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"Discard: Connection closed by peer", 0, 0, LOG_FILE);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-07-09 23:13:09 +00:00
|
|
|
|
2008-04-02 16:54:55 +00:00
|
|
|
DWORD WINAPI
|
|
|
|
DiscardHandler(VOID* sock_)
|
2007-07-09 23:13:09 +00:00
|
|
|
{
|
2008-04-02 16:54:55 +00:00
|
|
|
DWORD retVal = 0;
|
|
|
|
SOCKET sock = (SOCKET)sock_;
|
2007-07-09 23:13:09 +00:00
|
|
|
|
2013-04-13 21:28:10 +00:00
|
|
|
if (!ReceiveIncomingPackets(sock))
|
2007-07-09 23:13:09 +00:00
|
|
|
{
|
2013-04-13 21:28:10 +00:00
|
|
|
LogEvent(L"Discard: ReceiveIncomingPackets failed", 0, 0, LOG_FILE);
|
2008-04-02 16:54:55 +00:00
|
|
|
retVal = 1;
|
2007-07-09 23:13:09 +00:00
|
|
|
}
|
|
|
|
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"Discard: Shutting connection down", 0, 0, LOG_FILE);
|
2008-04-02 16:54:55 +00:00
|
|
|
if (ShutdownConnection(sock, TRUE))
|
|
|
|
{
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"Discard: Connection is down.", 0, 0, LOG_FILE);
|
2008-04-02 16:54:55 +00:00
|
|
|
}
|
2007-07-09 23:13:09 +00:00
|
|
|
else
|
|
|
|
{
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"Discard: Connection shutdown failed", 0, 0, LOG_FILE);
|
2008-04-02 16:54:55 +00:00
|
|
|
retVal = 1;
|
2007-07-09 23:13:09 +00:00
|
|
|
}
|
|
|
|
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"Discard: Terminating thread", 0, 0, LOG_FILE);
|
2008-04-02 16:54:55 +00:00
|
|
|
ExitThread(retVal);
|
2007-07-09 23:13:09 +00:00
|
|
|
}
|