ReactOS  0.4.13-dev-79-gcd489d8
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 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define CloseHandle
Definition: compat.h:398
char CHAR
Definition: xmlstorage.h:175
VOID GetAnswerToRequest(LPTSTR lpRequest, LPTSTR lpReply, LPDWORD lpcbReplyBytes)
Definition: npserver.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI FlushFileBuffers(IN HANDLE hFile)
Definition: fileinfo.c:175
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI DisconnectNamedPipe(HANDLE hNamedPipe)
Definition: npipe.c:961
#define BUFSIZE
Definition: npserver.c:7
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123

Referenced by main().

◆ main()

int main ( int argc  ,
char argv[] 
)

hosttype.c Copyright (C) 2002 by Brian Palmer brian.nosp@m.p@sg.nosp@m.inet..nosp@m.com

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,
44  PIPE_WAIT,
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 
63  DisconnectNamedPipe(hPipe);
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 CreateNamedPipe
Definition: winbase.h:3571
#define PIPE_UNLIMITED_INSTANCES
Definition: winbase.h:175
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:707
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define PIPE_TYPE_MESSAGE
Definition: winbase.h:168
#define PIPE_WAIT
Definition: winbase.h:171
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define PIPE_TIMEOUT
Definition: npserver.c:8
CHAR * LPTSTR
Definition: xmlstorage.h:192
VOID InstanceThread(LPVOID)
Definition: npserver.c:87
unsigned int BOOL
Definition: ntddk_ex.h:94
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:112
smooth NULL
Definition: ftsmooth.c:416
#define PIPE_ACCESS_DUPLEX
Definition: winbase.h:164
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID MyErrExit(LPTSTR Message)
Definition: npserver.c:19
DWORD dwThreadId
Definition: fdebug.c:31
#define ERROR_PIPE_CONNECTED
Definition: winerror.h:352
BOOL WINAPI DisconnectNamedPipe(HANDLE hNamedPipe)
Definition: npipe.c:961
#define BUFSIZE
Definition: npserver.c:7
#define PIPE_READMODE_MESSAGE
Definition: winbase.h:170
#define TEXT(s)
Definition: k32.h:26
HANDLE hThread
Definition: wizard.c:27
BOOL WINAPI ConnectNamedPipe(IN HANDLE hNamedPipe, IN LPOVERLAPPED lpOverlapped)
Definition: npipe.c:701
#define printf
Definition: config.h:203

◆ MyErrExit()

VOID MyErrExit ( LPTSTR  Message)

Definition at line 19 of file npserver.c.

20 {
21 // MessageBox(NULL, Message, NULL, MB_OK);
22  puts(Message);
23  ExitProcess(0);
24 }
VOID WINAPI ExitProcess(IN UINT uExitCode)
Definition: proc.c:1517
CHAR Message[80]
Definition: alive.c:5
int puts(const char *string)
Definition: crtsupp.c:23

Referenced by main().

Variable Documentation

◆ xx