Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 038e044

Browse files
committed
Fix compilation and apply suggestions (part 4)
1 parent bf8c5fe commit 038e044

File tree

3 files changed

+35
-43
lines changed

3 files changed

+35
-43
lines changed

src/core/file_sys/archive_artic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ ResultVal<std::unique_ptr<FileBackend>> ArticArchive::OpenFile(const Path& path,
140140
client->ReportArticEvent(static_cast<u64>(report_artic_event) | (1ULL << 32));
141141
}
142142

143-
return std::make_unique<ArticFileBackend>(client, *handle_opt, *this, cache_provider, path);
143+
return std::make_unique<ArticFileBackend>(client, *handle_opt, *this, *cache_provider, path);
144144
}
145145

146146
Result ArticArchive::DeleteFile(const Path& path) const {

src/network/artic_base/artic_base_client.cpp

+31-37
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151

5252
// #define DISABLE_PING_TIMEOUT
5353

54-
namespace Network {
55-
namespace ArticBase {
54+
namespace Network::ArticBase {
5655

5756
using namespace std::chrono_literals;
5857

@@ -61,10 +60,9 @@ bool Client::Request::AddParameterS8(s8 parameter) {
6160
ARTICBASE_ERROR("Too many parameters added to method: {}", method_name);
6261
return false;
6362
}
64-
ArticBaseCommon::RequestParameter currParam;
65-
currParam.type = ArticBaseCommon::RequestParameterType::IN_INTEGER_8;
66-
*reinterpret_cast<s8*>(currParam.data) = parameter;
67-
parameters.push_back(currParam);
63+
auto& param = parameters.emplace_back();
64+
param.type = ArticBaseCommon::RequestParameterType::IN_INTEGER_8;
65+
memcpy(param.data, &parameter, sizeof(s8));
6866
return true;
6967
}
7068

@@ -73,10 +71,9 @@ bool Client::Request::AddParameterS16(s16 parameter) {
7371
ARTICBASE_ERROR("Too many parameters added to method: {}", method_name);
7472
return false;
7573
}
76-
ArticBaseCommon::RequestParameter currParam;
77-
currParam.type = ArticBaseCommon::RequestParameterType::IN_INTEGER_16;
78-
*reinterpret_cast<s16*>(currParam.data) = parameter;
79-
parameters.push_back(currParam);
74+
auto& param = parameters.emplace_back();
75+
param.type = ArticBaseCommon::RequestParameterType::IN_INTEGER_16;
76+
memcpy(param.data, &parameter, sizeof(s16));
8077
return true;
8178
}
8279

@@ -85,10 +82,9 @@ bool Client::Request::AddParameterS32(s32 parameter) {
8582
ARTICBASE_ERROR("Too many parameters added to method: {}", method_name);
8683
return false;
8784
}
88-
ArticBaseCommon::RequestParameter currParam;
89-
currParam.type = ArticBaseCommon::RequestParameterType::IN_INTEGER_32;
90-
*reinterpret_cast<s32*>(currParam.data) = parameter;
91-
parameters.push_back(currParam);
85+
auto& param = parameters.emplace_back();
86+
param.type = ArticBaseCommon::RequestParameterType::IN_INTEGER_32;
87+
memcpy(param.data, &parameter, sizeof(s32));
9288
return true;
9389
}
9490

@@ -97,10 +93,9 @@ bool Client::Request::AddParameterS64(s64 parameter) {
9793
ARTICBASE_ERROR("Too many parameters added to method: {}", method_name);
9894
return false;
9995
}
100-
ArticBaseCommon::RequestParameter currParam;
101-
currParam.type = ArticBaseCommon::RequestParameterType::IN_INTEGER_64;
102-
*reinterpret_cast<s64*>(currParam.data) = parameter;
103-
parameters.push_back(currParam);
96+
auto& param = parameters.emplace_back();
97+
param.type = ArticBaseCommon::RequestParameterType::IN_INTEGER_64;
98+
memcpy(param.data, &parameter, sizeof(s64));
10499
return true;
105100
}
106101

@@ -109,18 +104,18 @@ bool Client::Request::AddParameterBuffer(const void* buffer, size_t size) {
109104
ARTICBASE_ERROR("Too many parameters added to method: {}", method_name);
110105
return false;
111106
}
112-
ArticBaseCommon::RequestParameter currParam;
113-
if (size <= sizeof(currParam.data)) {
114-
currParam.type = ArticBaseCommon::RequestParameterType::IN_SMALL_BUFFER;
115-
memcpy(currParam.data, buffer, size);
116-
currParam.parameterSize = static_cast<u16>(size);
107+
auto& param = parameters.emplace_back();
108+
if (size <= sizeof(param.data)) {
109+
param.type = ArticBaseCommon::RequestParameterType::IN_SMALL_BUFFER;
110+
memcpy(param.data, buffer, size);
111+
param.parameterSize = static_cast<u16>(size);
117112
} else {
118-
currParam.type = ArticBaseCommon::RequestParameterType::IN_BIG_BUFFER;
119-
currParam.bigBufferID = static_cast<u16>(pending_big_buffers.size());
120-
*reinterpret_cast<s32*>(currParam.data) = static_cast<s32>(size);
113+
param.type = ArticBaseCommon::RequestParameterType::IN_BIG_BUFFER;
114+
param.bigBufferID = static_cast<u16>(pending_big_buffers.size());
115+
s32 size_32 = static_cast<s32>(size);
116+
memcpy(param.data, &size_32, sizeof(size_32));
121117
pending_big_buffers.push_back(std::make_pair(buffer, size));
122118
}
123-
parameters.push_back(currParam);
124119
return true;
125120
}
126121

@@ -152,7 +147,7 @@ bool Client::Connect() {
152147
if (connected)
153148
return true;
154149

155-
auto strToUInt = [](const std::string& str) -> int {
150+
auto str_to_int = [](const std::string& str) -> int {
156151
char* pEnd = NULL;
157152
unsigned long ul = ::strtoul(str.c_str(), &pEnd, 10);
158153
if (*pEnd)
@@ -203,7 +198,7 @@ bool Client::Connect() {
203198

204199
auto version = SendSimpleRequest("VERSION");
205200
if (version.has_value()) {
206-
int version_value = strToUInt(*version);
201+
int version_value = str_to_int(*version);
207202
if (version_value != SERVER_VERSION) {
208203
shutdown(main_socket, SHUT_RDWR);
209204
closesocket(main_socket);
@@ -222,7 +217,7 @@ bool Client::Connect() {
222217
auto max_work_size = SendSimpleRequest("MAXSIZE");
223218
int max_work_size_value = -1;
224219
if (max_work_size.has_value()) {
225-
max_work_size_value = strToUInt(*max_work_size);
220+
max_work_size_value = str_to_int(*max_work_size);
226221
}
227222
if (max_work_size_value < 0) {
228223
shutdown(main_socket, SHUT_RDWR);
@@ -236,7 +231,7 @@ bool Client::Connect() {
236231
auto max_params = SendSimpleRequest("MAXPARAM");
237232
int max_param_value = -1;
238233
if (max_params.has_value()) {
239-
max_param_value = strToUInt(*max_params);
234+
max_param_value = str_to_int(*max_params);
240235
}
241236
if (max_param_value < 0) {
242237
shutdown(main_socket, SHUT_RDWR);
@@ -259,7 +254,7 @@ bool Client::Connect() {
259254
std::string str_port;
260255
std::stringstream ss_port(*worker_ports);
261256
while (std::getline(ss_port, str_port, ',')) {
262-
int port = strToUInt(str_port);
257+
int port = str_to_int(str_port);
263258
if (port < 0 || port > USHRT_MAX) {
264259
shutdown(main_socket, SHUT_RDWR);
265260
closesocket(main_socket);
@@ -376,7 +371,7 @@ std::optional<Client::Response> Client::Send(Request& request) {
376371
}
377372

378373
std::unique_lock<std::mutex> cv_lk(resp.cv_mutex);
379-
resp.cv.wait(cv_lk, [&resp]() { return resp._done; });
374+
resp.cv.wait(cv_lk, [&resp]() { return resp.is_done; });
380375

381376
return std::optional<Client::Response>(std::move(resp.response));
382377
}
@@ -726,7 +721,7 @@ void Client::Handler::RunLoop() {
726721

727722
{
728723
std::scoped_lock<std::mutex> lk(pending_response->cv_mutex);
729-
pending_response->_done = true;
724+
pending_response->is_done = true;
730725
pending_response->cv.notify_one();
731726
}
732727
}
@@ -742,12 +737,11 @@ void Client::OnAllHandlersFinished() {
742737
std::scoped_lock l(recv_map_mutex);
743738
for (auto it = pending_responses.begin(); it != pending_responses.end(); it++) {
744739
std::scoped_lock l2(it->second->cv_mutex);
745-
it->second->_done = true;
740+
it->second->is_done = true;
746741
it->second->cv.notify_one();
747742
}
748743
pending_responses.clear();
749744
}
750745
}
751746

752-
} // namespace ArticBase
753-
} // namespace Network
747+
} // namespace Network::ArticBase

src/network/artic_base/artic_base_client.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ using SocketHolder = unsigned long long;
1919
using SocketHolder = int;
2020
#endif // _WIN32
2121

22-
namespace Network {
23-
namespace ArticBase {
22+
namespace Network::ArticBase {
2423

2524
class Client {
2625
public:
@@ -261,7 +260,7 @@ class Client {
261260
private:
262261
class PendingResponse {
263262
public:
264-
bool _done = false;
263+
bool is_done = false;
265264

266265
private:
267266
friend class Client;
@@ -282,5 +281,4 @@ class Client {
282281
std::atomic<size_t> running_handlers;
283282
void OnAllHandlersFinished();
284283
};
285-
} // namespace ArticBase
286-
} // namespace Network
284+
} // namespace Network::ArticBase

0 commit comments

Comments
 (0)