ReactOS 0.4.16-dev-329-g9223134
npserver.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <tchar.h>
Include dependency graph for npserver.c:

Go to the source code of this file.

Macros

#define BUFSIZE   1024
 
#define PIPE_TIMEOUT   1000
 

Functions

VOID InstanceThread (LPVOID)
 
VOID GetAnswerToRequest (LPTSTR lpRequest, LPTSTR lpReply, LPDWORD lpcbReplyBytes)
 
VOID MyErrExit (LPTSTR Message)
 
int main (int argc, char *argv[])
 

Variables

int xx = 0
 

Macro Definition Documentation

◆ BUFSIZE

#define BUFSIZE   1024

Definition at line 7 of file npserver.c.

◆ PIPE_TIMEOUT

#define PIPE_TIMEOUT   1000

Definition at line 8 of file npserver.c.

Function Documentation

◆ GetAnswerToRequest()

VOID GetAnswerToRequest ( LPTSTR  lpRequest,
LPTSTR  lpReply,
LPDWORD  lpcbReplyBytes 
)

Definition at line 13 of file npserver.c.

16{
17}

Referenced by InstanceThread().

◆ InstanceThread()

VOID InstanceThread ( LPVOID  lpvParam)

Definition at line 87 of file npserver.c.

88{
89 CHAR chRequest[BUFSIZE];
90 CHAR chReply[BUFSIZE];
91 DWORD cbBytesRead, cbReplyBytes, cbWritten;
92 BOOL fSuccess;
93 HANDLE hPipe;
94
95 hPipe = (HANDLE)lpvParam;
96 while (1)
97 {
98 fSuccess = ReadFile(hPipe,
99 chRequest,
100 BUFSIZE,
101 &cbBytesRead,
102 NULL);
103 if (!fSuccess || cbBytesRead == 0)
104 break;
105
106 GetAnswerToRequest(chRequest, chReply, &cbReplyBytes);
107
108 fSuccess = WriteFile(hPipe,
109 chReply,
110 cbReplyBytes,
111 &cbWritten,
112 NULL);
113 if (!fSuccess || cbReplyBytes != cbWritten)
114 break;
115 }
116
117 FlushFileBuffers(hPipe);
118 DisconnectNamedPipe(hPipe);
119 CloseHandle(hPipe);
120}
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:25
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI DisconnectNamedPipe(HANDLE hNamedPipe)
Definition: npipe.c:961
VOID GetAnswerToRequest(LPTSTR lpRequest, LPTSTR lpReply, LPDWORD lpcbReplyBytes)
Definition: npserver.c:13
#define BUFSIZE
Definition: npserver.c:7
PVOID HANDLE
Definition: typedefs.h:73
char CHAR
Definition: xmlstorage.h:175

Referenced by main().

◆ main()

int main ( int argc  ,
char argv[] 
)

Definition at line 31 of file npserver.c.

32{
33 BOOL fConnected;
35 HANDLE hPipe, hThread;
36 LPTSTR lpszPipename = TEXT("\\\\.\\pipe\\mynamedpipe");
37
38// for (;;)
39// {
40 hPipe = CreateNamedPipe(lpszPipename,
46 BUFSIZE,
47 BUFSIZE,
49 NULL);
50 if (hPipe == INVALID_HANDLE_VALUE)
51 {
52 printf("CreateNamedPipe() failed\n");
53 return 0;
54 }
55
56 fConnected = ConnectNamedPipe(hPipe,
57 NULL) ? TRUE : (GetLastError () ==
59 if (fConnected)
60 {
61 printf("Pipe connected!\n");
62
64
65#if 0
67 0,
69 (LPVOID) hPipe,
70 0,
71 &dwThreadId);
72 if (hThread == NULL)
73 MyErrExit("CreateThread");
74#endif
75 }
76 else
77 {
78// CloseHandle(hPipe);
79 }
80// }
81
82 CloseHandle(hPipe);
83
84 return 0;
85}
#define TRUE
Definition: types.h:120
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
DWORD dwThreadId
Definition: fdebug.c:31
#define printf
Definition: freeldr.h:97
#define TEXT(s)
Definition: k32.h:26
HANDLE hThread
Definition: wizard.c:28
BOOL WINAPI ConnectNamedPipe(IN HANDLE hNamedPipe, IN LPOVERLAPPED lpOverlapped)
Definition: npipe.c:701
#define PIPE_TIMEOUT
Definition: npserver.c:8
VOID MyErrExit(LPTSTR Message)
Definition: npserver.c:19
VOID InstanceThread(LPVOID)
Definition: npserver.c:87
#define CreateNamedPipe
Definition: winbase.h:3782
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define PIPE_ACCESS_DUPLEX
Definition: winbase.h:165
#define PIPE_WAIT
Definition: winbase.h:172
#define PIPE_READMODE_MESSAGE
Definition: winbase.h:171
#define PIPE_TYPE_MESSAGE
Definition: winbase.h:169
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:754
#define PIPE_UNLIMITED_INSTANCES
Definition: winbase.h:176
#define ERROR_PIPE_CONNECTED
Definition: winerror.h:352
CHAR * LPTSTR
Definition: xmlstorage.h:192

◆ MyErrExit()

VOID MyErrExit ( LPTSTR  Message)

Definition at line 19 of file npserver.c.

20{
21// MessageBox(NULL, Message, NULL, MB_OK);
23 ExitProcess(0);
24}
int puts(const char *string)
Definition: crtsupp.c:23
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1487
static const WCHAR Message[]
Definition: register.c:74

Referenced by main().

Variable Documentation

◆ xx