forked from frmeier/psi46test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe.h
53 lines (47 loc) · 1.05 KB
/
pipe.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// pipe.h
#pragma once
#include "windows.h"
#include "rpc.h"
class CPipeServer : public CRpcIo
{
HANDLE hPipe;
public:
CPipeServer() : hPipe(INVALID_HANDLE_VALUE) {}
~CPipeServer() {}
bool Create(const char *name);
void WaitConnection();
void Close();
void Read(void *buffer, unsigned int size)
{
DWORD n;
if (!ReadFile(hPipe, buffer, size, &n, NULL)) throw int(1);
}
void Flush() {}
void Clear() {}
void Write(const void *buffer, unsigned int size)
{
DWORD n;
if (!WriteFile(hPipe, buffer, size, &n, NULL)) throw int(2);
}
};
class CPipeClient : public CRpcIo
{
HANDLE hPipe;
public:
CPipeClient() : hPipe(INVALID_HANDLE_VALUE) {}
~CPipeClient() {}
bool Open(const char *name);
void Close();
void Read(void *buffer, unsigned int size)
{
DWORD n;
if (!ReadFile(hPipe, buffer, size, &n, NULL)) throw int(1);
}
void Flush() {}
void Clear() {}
void Write(const void *buffer, unsigned int size)
{
DWORD n;
if (!WriteFile(hPipe, buffer, size, &n, NULL)) throw int(2);
}
};