forked from xNVSE/NVSE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPipeClient.cpp
More file actions
60 lines (47 loc) · 1.06 KB
/
Copy pathIPipeClient.cpp
File metadata and controls
60 lines (47 loc) · 1.06 KB
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
54
55
56
57
58
59
60
#include "IPipeClient.h"
IPipeClient::IPipeClient()
:m_pipe(INVALID_HANDLE_VALUE)
{
//
}
IPipeClient::~IPipeClient()
{
Close();
}
bool IPipeClient::Open(const char * name)
{
Close();
m_pipe = CreateFile(
name,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
return m_pipe != INVALID_HANDLE_VALUE;
}
void IPipeClient::Close(void)
{
if(m_pipe != INVALID_HANDLE_VALUE)
{
CloseHandle(m_pipe);
m_pipe = INVALID_HANDLE_VALUE;
}
}
bool IPipeClient::ReadMessage(UInt8 * buf, UInt32 length)
{
UInt32 bytesRead;
ReadFile(m_pipe, buf, length, &bytesRead, NULL);
IPipeServer::MessageHeader * header = (IPipeServer::MessageHeader *)buf;
return
(bytesRead >= sizeof(IPipeServer::MessageHeader)) && // has a valid header
(bytesRead >= (sizeof(IPipeServer::MessageHeader) + header->length));
}
bool IPipeClient::WriteMessage(IPipeServer::MessageHeader * msg)
{
UInt32 bytesWritten;
UInt32 length = sizeof(IPipeServer::MessageHeader) + msg->length;
WriteFile(m_pipe, msg, length, &bytesWritten, NULL);
return bytesWritten >= length;
}