Silence most of the msvc warnings
[reactos.git] / reactos / services / tcpsvcs / discard.c
1 /*
2 * ReactOS Services
3 * Copyright (C) 2005 ReactOS Team
4 *
5 * LICENCE: GPL - See COPYING in the top level directory
6 * PROJECT: ReactOS simple TCP/IP services
7 * FILE: apps/utils/net/tcpsvcs/discard.c
8 * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
9 * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
10 * REVISIONS:
11 * GM 04/10/05 Created
12 *
13 */
14
15 #include "tcpsvcs.h"
16
17 extern BOOL bShutDown;
18
19 DWORD WINAPI DiscardHandler(VOID* Sock_)
20 {
21 DWORD RetVal = 0;
22 SOCKET Sock = (SOCKET)Sock_;
23
24 if (!RecieveIncomingPackets(Sock))
25 {
26 LogEvent(_T("Discard: RecieveIncomingPackets failed\n"), 0, FALSE);
27 RetVal = 1;
28 }
29
30 LogEvent(_T("Discard: Shutting connection down...\n"), 0, FALSE);
31 if (ShutdownConnection(Sock, TRUE))
32 LogEvent(_T("Discard: Connection is down.\n"), 0, FALSE);
33 else
34 {
35 LogEvent(_T("Discard: Connection shutdown failed\n"), 0, FALSE);
36 RetVal = 1;
37 }
38
39 LogEvent(_T("Discard: Terminating thread\n"), 0, FALSE);
40 ExitThread(RetVal);
41 }
42
43
44
45 BOOL RecieveIncomingPackets(SOCKET Sock)
46 {
47 TCHAR ReadBuffer[BUF];
48 TCHAR buf[256];
49 INT ReadBytes;
50
51 do
52 {
53 ReadBytes = recv(Sock, ReadBuffer, BUF, 0);
54 if (ReadBytes > 0)
55 {
56 _stprintf(buf, _T("Received %d bytes from client\n"), ReadBytes);
57 LogEvent(buf, 0, FALSE);
58 }
59 else if (ReadBytes == SOCKET_ERROR)
60 {
61 _stprintf(buf, ("Socket Error: %d\n"), WSAGetLastError());
62 LogEvent(buf, 0, TRUE);
63 return FALSE;
64 }
65 } while ((ReadBytes > 0) && (! bShutDown));
66
67 if (! bShutDown)
68 LogEvent(_T("Discard: Connection closed by peer.\n"), 0, FALSE);
69
70 return TRUE;
71 }