-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.cpp
46 lines (39 loc) · 870 Bytes
/
client.cpp
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
#include <windows.h>
#include <sstream>
#include <string>
#include <vector>
#include "common.h"
#include "client.h"
#include "serialization.h"
using namespace std;
void sendHeader(HANDLE h, string key) {
log("Sending header.");
auto headerData{ serialize(Action { Type::Send, key }) };
DWORD bytesWritten{ 0 };
const bool success = WriteFile(
h,
&headerData[0],
headerData.size(),
&bytesWritten,
nullptr // not overlapped i.e. synchronous
);
if (!success) {
throw GetLastError();
}
log("Sent header.");
}
bool awaitSendSuccess(HANDLE h) {
vector<char> buf(bufSize);
DWORD bytesRead;
const bool readSuccess = ReadFile(
h,
buf.data(),
buf.size(),
&bytesRead,
nullptr
);
if (!readSuccess) {
throw GetLastError();
}
return string{ buf.data(), bytesRead } == saveSuccessStatus;
}