- Don't call winsock initialiser for each seperate server thread
[reactos.git] / reactos / apps / utils / net / tcpsvcs / discard.c
1 #include <stdio.h>
2 #include <winsock2.h>
3 #include <tchar.h>
4 #include "tcpsvcs.h"
5
6 DWORD WINAPI DiscardHandler(VOID* Sock_)
7 {
8 DWORD Retval = 0;
9 SOCKET Sock = (SOCKET)Sock_;
10
11 if (!RecieveIncomingPackets(Sock))
12 {
13 _tprintf(_T("RecieveIncomingPackets failed\n"));
14 Retval = 3;
15 }
16
17 _tprintf(_T("Shutting connection down...\n"));
18 if (ShutdownConnection(Sock, TRUE))
19 {
20 _tprintf(_T("Connection is down.\n"));
21 }
22 else
23 {
24 _tprintf(_T("Connection shutdown failed\n"));
25 Retval = 3;
26 }
27 _tprintf(_T("Terminating discard thread\n"));
28 ExitThread(0);
29
30 return Retval;
31 }
32
33
34
35 BOOL RecieveIncomingPackets(SOCKET Sock)
36 {
37 TCHAR ReadBuffer[BUF];
38 INT ReadBytes;
39
40 do
41 {
42 ReadBytes = recv(Sock, ReadBuffer, BUF, 0);
43 if (ReadBytes > 0)
44 _tprintf(_T("Received %d bytes from client\n"), ReadBytes);
45 else if (ReadBytes == SOCKET_ERROR)
46 {
47 _tprintf(("Socket Error: %d\n"), WSAGetLastError());
48 return FALSE;
49 }
50 } while (ReadBytes > 0);
51
52 _tprintf(("Connection closed by peer.\n"));
53 return TRUE;
54 }