Don't display exit code for none fatal info
[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 DWORD WINAPI DiscardHandler(VOID* Sock_)
18 {
19 DWORD RetVal = 0;
20 SOCKET Sock = (SOCKET)Sock_;
21
22 if (!RecieveIncomingPackets(Sock))
23 {
24 LogEvent(_T("Discard: RecieveIncomingPackets failed\n"), 0, FALSE);
25 RetVal = -1;
26 }
27
28 LogEvent(_T("Discard: Shutting connection down...\n"), 0, FALSE);
29 if (ShutdownConnection(Sock, TRUE))
30 LogEvent(_T("Discard: Connection is down.\n"), 0, FALSE);
31 else
32 {
33 LogEvent(_T("Discard: Connection shutdown failed\n"), 0, FALSE);
34 RetVal = -1;
35 }
36
37 LogEvent(_T("Discard: Terminating thread\n"), 0, FALSE);
38 ExitThread(RetVal);
39 }
40
41
42
43 BOOL RecieveIncomingPackets(SOCKET Sock)
44 {
45 TCHAR ReadBuffer[BUF];
46 TCHAR temp[512]; // temp for holding LogEvent text
47 INT ReadBytes;
48
49 do
50 {
51 ReadBytes = recv(Sock, ReadBuffer, BUF, 0);
52 if (ReadBytes > 0)
53 {
54 _stprintf(temp, _T("Received %d bytes from client\n"), ReadBytes);
55 LogEvent(temp, 0, FALSE);
56 }
57 else if (ReadBytes == SOCKET_ERROR)
58 {
59 _stprintf(temp, ("Socket Error: %d\n"), WSAGetLastError());
60 LogEvent(temp, 0, TRUE);
61 return FALSE;
62 }
63 } while (ReadBytes > 0);
64
65 LogEvent(_T("Discard: Connection closed by peer.\n"), 0, FALSE);
66 return TRUE;
67 }