[SHELL-EXPERIMENTS]
[reactos.git] / base / services / tcpsvcs / discard.c
1 /*
2 * PROJECT: ReactOS simple TCP/IP services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: /base/services/tcpsvcs/discard.c
5 * PURPOSE: Receives input from a client and discards it
6 * COPYRIGHT: Copyright 2005 - 2008 Ged Murphy <gedmurphy@reactos.org>
7 *
8 */
9
10 #include "tcpsvcs.h"
11
12 #define BUFSIZE 1024
13
14 static BOOL
15 ReceiveIncomingPackets(SOCKET sock)
16 {
17 CHAR readBuffer[BUFSIZE];
18 INT readBytes;
19
20 do
21 {
22 readBytes = recv(sock, readBuffer, BUFSIZE, 0);
23 if (readBytes > 0)
24 {
25 TCHAR logBuf[256];
26
27 swprintf(logBuf, L"Discard: Received %d bytes from client", readBytes);
28 LogEvent(logBuf, 0, 0, LOG_FILE);
29 }
30 else if (readBytes == SOCKET_ERROR)
31 {
32 LogEvent(L"Discard: Socket Error", WSAGetLastError(), 0, LOG_ERROR);
33 return FALSE;
34 }
35 } while ((readBytes > 0) && (!bShutdown));
36
37 if (!bShutdown)
38 LogEvent(L"Discard: Connection closed by peer", 0, 0, LOG_FILE);
39
40 return TRUE;
41 }
42
43 DWORD WINAPI
44 DiscardHandler(VOID* sock_)
45 {
46 DWORD retVal = 0;
47 SOCKET sock = (SOCKET)sock_;
48
49 if (!ReceiveIncomingPackets(sock))
50 {
51 LogEvent(L"Discard: ReceiveIncomingPackets failed", 0, 0, LOG_FILE);
52 retVal = 1;
53 }
54
55 LogEvent(L"Discard: Shutting connection down", 0, 0, LOG_FILE);
56 if (ShutdownConnection(sock, TRUE))
57 {
58 LogEvent(L"Discard: Connection is down.", 0, 0, LOG_FILE);
59 }
60 else
61 {
62 LogEvent(L"Discard: Connection shutdown failed", 0, 0, LOG_FILE);
63 retVal = 1;
64 }
65
66 LogEvent(L"Discard: Terminating thread", 0, 0, LOG_FILE);
67 ExitThread(retVal);
68 }