ReactOS  0.4.13-dev-92-gf251225
pipespy.cpp File Reference
#include <process.h>
#include <windows.h>
#include <stdio.h>
Include dependency graph for pipespy.cpp:

Go to the source code of this file.

Classes

struct  _READ_OVERLAPPED
 

Typedefs

typedef struct _READ_OVERLAPPED READ_OVERLAPPED
 

Enumerations

enum  { PIPEBUF_INITIAL_SIZE = 4096, PIPEBUF_MAX_SIZE = 16384 }
 

Functions

void dumphex (const char *buf, int len, int pos)
 
VOID WINAPI WritePipeCompletion (DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped)
 
VOID WINAPI ReadPipeCompletion (DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped)
 
void __cdecl pipeserver (void *param)
 
int main (int ac, char **av)
 

Variables

HANDLE g_DebugServerPipe
 
HANDLE g_DebugClientPipe
 
CRITICAL_SECTION g_OutputLock
 

Typedef Documentation

◆ READ_OVERLAPPED

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
PIPEBUF_INITIAL_SIZE 
PIPEBUF_MAX_SIZE 

Definition at line 52 of file pipespy.cpp.

52  {
53  PIPEBUF_INITIAL_SIZE = 4096,
54  PIPEBUF_MAX_SIZE = 16384
55 };

Function Documentation

◆ dumphex()

void dumphex ( const char buf,
int  len,
int  pos 
)

Definition at line 32 of file pipespy.cpp.

33 {
34  int i, j;
35  for(j = 0; j < len; j += 16) {
36  for(i = 0; i < 16; i++) {
37  if(i + j < len)
38  printf("%02x%c", (unsigned char)buf[i + j], j + i + 1 == pos ? '*' : ' ');
39  else
40  printf(" ");
41  }
42  for(i = 0; i < 16; i++) {
43  if(i + j < len)
44  printf("%c", buf[i + j] >= ' ' ? buf[i + j] : '.');
45  else
46  printf(" ");
47  }
48  printf("\n");
49  }
50 }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
GLenum GLsizei len
Definition: glext.h:6722
#define printf
Definition: config.h:203

Referenced by ReadPipeCompletion().

◆ main()

int main ( int  ac,
char **  av 
)

Definition at line 152 of file pipespy.cpp.

153 {
154  if(ac != 3) {
155  printf("syntax: pipespy serverpipe clientpipe\n");
156  return 0;
157  }
158 
160  1, 4096, 4096, NMPWAIT_WAIT_FOREVER, 0);
161 
163  printf("Error %u creating server pipe\n", GetLastError());
164  return 0;
165  }
166 
168  1, 4096, 4096, NMPWAIT_WAIT_FOREVER, 0);
169 
171  printf("Error %u creating client pipe\n", GetLastError());
173  return 0;
174  }
175 
180  return 0;
181 }
#define CreateNamedPipe
Definition: winbase.h:3571
#define CloseHandle
Definition: compat.h:398
#define PIPE_WAIT
Definition: winbase.h:171
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HANDLE g_DebugServerPipe
Definition: pipespy.cpp:29
void __cdecl pipeserver(void *param)
Definition: pipespy.cpp:116
HANDLE g_DebugClientPipe
Definition: pipespy.cpp:29
#define NMPWAIT_WAIT_FOREVER
Definition: winbase.h:133
#define PIPE_TYPE_BYTE
Definition: winbase.h:167
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
#define PIPE_ACCESS_DUPLEX
Definition: winbase.h:164
CRITICAL_SECTION g_OutputLock
Definition: pipespy.cpp:30
_CRTIMP uintptr_t __cdecl _beginthread(_In_ void(__cdecl *_StartAddress)(void *), _In_ unsigned _StackSize, _In_opt_ void *_ArgList)
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
#define printf
Definition: config.h:203
#define PIPE_READMODE_BYTE
Definition: winbase.h:169

◆ pipeserver()

void __cdecl pipeserver ( void param)

Definition at line 116 of file pipespy.cpp.

117 {
118  READ_OVERLAPPED ReadOverlapped;
119 
120  ReadOverlapped.Pipe = (HANDLE)param, ReadOverlapped.OtherPipe = ReadOverlapped.Pipe == g_DebugServerPipe ? g_DebugClientPipe : g_DebugServerPipe;
121  ReadOverlapped.Server = ReadOverlapped.Pipe == g_DebugServerPipe;
122  ReadOverlapped.Buffer = (char*)malloc(PIPEBUF_INITIAL_SIZE);
123 
124  for(;;) {
125  if(!ConnectNamedPipe(ReadOverlapped.Pipe, 0) && GetLastError() != ERROR_PIPE_CONNECTED) {
126  printf(ReadOverlapped.Server ? "Server> Error %u accepting pipe connection\n" : "Client> Error %u accepting pipe connection\n",
127  GetLastError());
128  break;
129  }
130 
131  ReadOverlapped.Connected = true;
132  printf(ReadOverlapped.Server ? "Server> Connected\n" : "Client> Connected\n");
133 
134  ZeroMemory(&ReadOverlapped.ReadOverlapped, sizeof(OVERLAPPED));
135  ReadFileEx(ReadOverlapped.Pipe, ReadOverlapped.Buffer, PIPEBUF_INITIAL_SIZE, &ReadOverlapped.ReadOverlapped, ReadPipeCompletion);
136 
137  do {
139  } while(ReadOverlapped.Connected) ;
140 
141  DisconnectNamedPipe(ReadOverlapped.Pipe);
142  printf(ReadOverlapped.Server ? "Server> Disconnected\n" : "Client> Disconnected\n");
143  }
144 
145  printf(ReadOverlapped.Server ? "Server> Shutting down\n" : "Client> Shutting down\n");
146 
147  free(ReadOverlapped.Buffer);
148  CloseHandle(ReadOverlapped.Pipe);
149  SleepEx(0, TRUE);
150 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define free
Definition: debug_ros.c:5
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
HANDLE g_DebugServerPipe
Definition: pipespy.cpp:29
HANDLE g_DebugClientPipe
Definition: pipespy.cpp:29
BOOL WINAPI ReadFileEx(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead OPTIONAL, IN LPOVERLAPPED lpOverlapped, IN LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
Definition: rw.c:299
DWORD WINAPI SleepEx(IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:748
GLfloat param
Definition: glext.h:5796
PVOID HANDLE
Definition: typedefs.h:71
#define ERROR_PIPE_CONNECTED
Definition: winerror.h:352
BOOL WINAPI DisconnectNamedPipe(HANDLE hNamedPipe)
Definition: npipe.c:961
VOID WINAPI ReadPipeCompletion(DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped)
Definition: pipespy.cpp:76
HANDLE OtherPipe
Definition: pipespy.cpp:60
#define malloc
Definition: debug_ros.c:4
#define INFINITE
Definition: serial.h:102
BOOL WINAPI ConnectNamedPipe(IN HANDLE hNamedPipe, IN LPOVERLAPPED lpOverlapped)
Definition: npipe.c:701
OVERLAPPED ReadOverlapped
Definition: pipespy.cpp:58
#define printf
Definition: config.h:203

Referenced by main().

◆ ReadPipeCompletion()

VOID WINAPI ReadPipeCompletion ( DWORD  dwErrorCode,
DWORD  dwNumberOfBytesTransferred,
LPOVERLAPPED  lpOverlapped 
)

Definition at line 76 of file pipespy.cpp.

77 {
78  READ_OVERLAPPED* ReadOverlapped = (READ_OVERLAPPED*)lpOverlapped;
79  LPOVERLAPPED WriteOverlapped;
80 
82 
83  if(dwErrorCode) {
84  printf(ReadOverlapped->Server ? "Server> Error %u reading from pipe\n" : "Client> Error %u reading from pipe\n", dwErrorCode);
85  ReadOverlapped->Connected = false;
86  } else {
87  SYSTEMTIME SystemTime;
88 
89  GetLocalTime(&SystemTime);
90  printf(ReadOverlapped->Server ? "Server> [%02u:%02u:%02u.%03u] Received %u byte message:\n" : "Client> [%02u:%02u:%02u.%03u] Received %u byte message:\n",
91  SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, SystemTime.wMilliseconds, dwNumberOfBytesTransferred);
92  dumphex(ReadOverlapped->Buffer, (int)dwNumberOfBytesTransferred, -1);
93  printf("\n");
94  }
95 
97 
98  WriteOverlapped = (LPOVERLAPPED)malloc(sizeof(OVERLAPPED)+dwNumberOfBytesTransferred);
99 
100  if(!WriteOverlapped)
101  printf(ReadOverlapped->Server ? "Server> Out of memory\n" : "Client> Out of memory\n");
102  else {
103  ZeroMemory(WriteOverlapped, sizeof(OVERLAPPED));
104  WriteOverlapped->hEvent = (HANDLE)ReadOverlapped->Server;
105  memcpy(((char*)WriteOverlapped)+sizeof(OVERLAPPED), ReadOverlapped->Buffer, dwNumberOfBytesTransferred);
106  WriteFileEx(ReadOverlapped->OtherPipe, ((char*)WriteOverlapped)+sizeof(OVERLAPPED), dwNumberOfBytesTransferred, WriteOverlapped,
108  }
109 
110  if(!dwErrorCode) {
111  ZeroMemory(ReadOverlapped, sizeof(OVERLAPPED));
112  ReadFileEx(ReadOverlapped->Pipe, ReadOverlapped->Buffer, PIPEBUF_INITIAL_SIZE, &ReadOverlapped->ReadOverlapped, ReadPipeCompletion);
113  }
114 }
struct _OVERLAPPED OVERLAPPED
struct _OVERLAPPED * LPOVERLAPPED
#define ZeroMemory
Definition: winbase.h:1635
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
VOID WINAPI WritePipeCompletion(DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped)
Definition: pipespy.cpp:65
BOOL WINAPI ReadFileEx(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead OPTIONAL, IN LPOVERLAPPED lpOverlapped, IN LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
Definition: rw.c:299
HANDLE hEvent
Definition: winbase.h:792
WORD wMinute
Definition: winbase.h:875
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:276
PVOID HANDLE
Definition: typedefs.h:71
WORD wSecond
Definition: winbase.h:876
WORD wMilliseconds
Definition: winbase.h:877
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
VOID WINAPI ReadPipeCompletion(DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped)
Definition: pipespy.cpp:76
void dumphex(const char *buf, int len, int pos)
Definition: pipespy.cpp:32
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:90
CRITICAL_SECTION g_OutputLock
Definition: pipespy.cpp:30
WORD wHour
Definition: winbase.h:874
HANDLE OtherPipe
Definition: pipespy.cpp:60
#define malloc
Definition: debug_ros.c:4
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
BOOL WINAPI WriteFileEx(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, IN LPOVERLAPPED lpOverlapped, IN LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
Definition: rw.c:262
OVERLAPPED ReadOverlapped
Definition: pipespy.cpp:58
#define printf
Definition: config.h:203

Referenced by pipeserver().

◆ WritePipeCompletion()

VOID WINAPI WritePipeCompletion ( DWORD  dwErrorCode,
DWORD  dwNumberOfBytesTransferred,
LPOVERLAPPED  lpOverlapped 
)

Definition at line 65 of file pipespy.cpp.

66 {
67  if(dwErrorCode) {
69  printf(lpOverlapped->hEvent ? "Server> Error %u writing to client pipe\n" : "Client> Error %u writing to server pipe\n", dwErrorCode);
71  }
72 
73  free((void*)lpOverlapped);
74 }
#define free
Definition: debug_ros.c:5
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:90
CRITICAL_SECTION g_OutputLock
Definition: pipespy.cpp:30
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define printf
Definition: config.h:203

Referenced by ReadPipeCompletion().

Variable Documentation

◆ g_DebugClientPipe

HANDLE g_DebugClientPipe

Definition at line 29 of file pipespy.cpp.

Referenced by main(), and pipeserver().

◆ g_DebugServerPipe

HANDLE g_DebugServerPipe

Definition at line 29 of file pipespy.cpp.

Referenced by main(), and pipeserver().

◆ g_OutputLock

CRITICAL_SECTION g_OutputLock

Definition at line 30 of file pipespy.cpp.

Referenced by main(), ReadPipeCompletion(), and WritePipeCompletion().