ReactOS  0.4.12-dev-75-g00dd17e
discard.c File Reference
#include "tcpsvcs.h"
Include dependency graph for discard.c:

Go to the source code of this file.

Macros

#define BUFSIZE   1024
 

Functions

static BOOL ReceiveIncomingPackets (SOCKET sock)
 
DWORD WINAPI DiscardHandler (VOID *sock_)
 

Macro Definition Documentation

◆ BUFSIZE

#define BUFSIZE   1024

Definition at line 12 of file discard.c.

Referenced by main(), ReadFromPipeThread(), ReceiveIncomingPackets(), and WriteToPipeThread().

Function Documentation

◆ DiscardHandler()

DWORD WINAPI DiscardHandler ( VOID sock_)

Definition at line 44 of file discard.c.

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 }
#define TRUE
Definition: types.h:120
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:327
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL ShutdownConnection(SOCKET sock, BOOL bRec)
Definition: skelserver.c:126
static const WCHAR L[]
Definition: oid.c:1087
VOID LogEvent(LPCWSTR lpMsg, DWORD errNum, DWORD exitCode, UINT flags)
Definition: log.c:196
Definition: tcpcore.h:1455
static BOOL ReceiveIncomingPackets(SOCKET sock)
Definition: discard.c:15
UINT_PTR SOCKET
Definition: winsock.h:47

◆ ReceiveIncomingPackets()

static BOOL ReceiveIncomingPackets ( SOCKET  sock)
static

Definition at line 15 of file discard.c.

Referenced by DiscardHandler().

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 }
volatile BOOL bShutdown
Definition: tcpsvcs.c:16
#define SOCKET_ERROR
Definition: winsock.h:333
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
int32_t INT
Definition: typedefs.h:56
#define LOG_ERROR
Definition: tcpsvcs.h:16
char TCHAR
Definition: xmlstorage.h:189
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static const WCHAR L[]
Definition: oid.c:1087
VOID LogEvent(LPCWSTR lpMsg, DWORD errNum, DWORD exitCode, UINT flags)
Definition: log.c:196
Definition: tcpcore.h:1455
#define BUFSIZE
Definition: discard.c:12
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23