Skip to content

Commit e566a3c

Browse files
committed
make format
1 parent e933882 commit e566a3c

File tree

2 files changed

+38
-42
lines changed

2 files changed

+38
-42
lines changed

vpr/src/server/gateio.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static ActivityStatus check_client_connection(sockpp::tcp6_acceptor& tcp_server,
1616
sockpp::inet6_address peer;
1717
sockpp::tcp6_socket client = tcp_server.accept(&peer);
1818
if (client) {
19-
logger.queue(LogLevel::Info, "client", client.address().to_string() , "connection accepted");
19+
logger.queue(LogLevel::Info, "client", client.address().to_string(), "connection accepted");
2020
client.set_non_blocking(true);
2121
client_opt = std::move(client);
2222

@@ -38,12 +38,12 @@ static ActivityStatus handle_sending_data(sockpp::tcp6_socket& client, std::mute
3838
if (bytes_sent <= task->orig_reponse_bytes_num()) {
3939
task->chop_num_sent_bytes_from_response_buffer(bytes_sent);
4040
logger.queue(LogLevel::Detail,
41-
"sent chunk:", get_pretty_size_str_from_bytes_num(bytes_sent),
42-
"from", get_pretty_size_str_from_bytes_num(task->orig_reponse_bytes_num()),
43-
"left:", get_pretty_size_str_from_bytes_num(task->response_buffer().size()));
41+
"sent chunk:", get_pretty_size_str_from_bytes_num(bytes_sent),
42+
"from", get_pretty_size_str_from_bytes_num(task->orig_reponse_bytes_num()),
43+
"left:", get_pretty_size_str_from_bytes_num(task->response_buffer().size()));
4444
status = ActivityStatus::CLIENT_ACTIVITY;
4545
}
46-
} catch(...) {
46+
} catch (...) {
4747
logger.queue(LogLevel::Detail, "error while writing chunk");
4848
status = ActivityStatus::COMMUNICATION_PROBLEM;
4949
}
@@ -57,7 +57,7 @@ static ActivityStatus handle_sending_data(sockpp::tcp6_socket& client, std::mute
5757
std::size_t tasks_num_before_removing = send_tasks.size();
5858

5959
auto partition_iter = std::partition(send_tasks.begin(), send_tasks.end(),
60-
[](const TaskPtr& task) { return !task->is_response_fully_sent(); });
60+
[](const TaskPtr& task) { return !task->is_response_fully_sent(); });
6161
send_tasks.erase(partition_iter, send_tasks.end());
6262
bool is_removing_took_place = tasks_num_before_removing != send_tasks.size();
6363
if (!send_tasks.empty() && is_removing_took_place) {
@@ -72,7 +72,7 @@ static ActivityStatus handle_receiving_data(sockpp::tcp6_socket& client, comm::T
7272
std::size_t bytes_actually_received{0};
7373
try {
7474
bytes_actually_received = client.read_n(&received_message[0], CHUNK_MAX_BYTES_NUM);
75-
} catch(...) {
75+
} catch (...) {
7676
logger.queue(LogLevel::Error, "fail to receiving");
7777
status = ActivityStatus::COMMUNICATION_PROBLEM;
7878
}
@@ -90,7 +90,7 @@ static ActivityStatus handle_telegrams(std::vector<comm::TelegramFramePtr>& tele
9090
ActivityStatus status = ActivityStatus::WAITING_ACTIVITY;
9191
telegram_frames.clear();
9292
telegram_buff.take_telegram_frames(telegram_frames);
93-
for (const comm::TelegramFramePtr& telegram_frame: telegram_frames) {
93+
for (const comm::TelegramFramePtr& telegram_frame : telegram_frames) {
9494
// process received data
9595
std::string message{telegram_frame->body};
9696
bool is_echo_telegram = false;
@@ -108,7 +108,7 @@ static ActivityStatus handle_telegrams(std::vector<comm::TelegramFramePtr>& tele
108108
if (job_id_opt && cmd_opt && options_opt) {
109109
TaskPtr task = std::make_unique<Task>(job_id_opt.value(), static_cast<comm::CMD>(cmd_opt.value()), options_opt.value());
110110
const comm::TelegramHeader& header = telegram_frame->header;
111-
logger.queue(LogLevel::Info, "received:", header.info(), task->info(/*skipDuration*/true));
111+
logger.queue(LogLevel::Info, "received:", header.info(), task->info(/*skipDuration*/ true));
112112
std::unique_lock<std::mutex> lock(tasks_mutex);
113113
received_tasks.push_back(std::move(task));
114114
} else {
@@ -134,7 +134,7 @@ static ActivityStatus handle_client_alive_tracker(sockpp::tcp6_socket& client, s
134134
logger.queue(LogLevel::Detail, "sent", comm::ECHO_TELEGRAM_BODY);
135135
client_alive_tracker_ptr->on_echo_sent();
136136
}
137-
} catch(...) {
137+
} catch (...) {
138138
logger.queue(LogLevel::Debug, "fail to sent", comm::ECHO_TELEGRAM_BODY);
139139
status = ActivityStatus::COMMUNICATION_PROBLEM;
140140
}
@@ -160,7 +160,6 @@ static void handle_activity_status(ActivityStatus status, std::unique_ptr<Client
160160
}
161161
}
162162

163-
164163
GateIO::GateIO() {
165164
m_is_running.store(false);
166165
}
@@ -189,7 +188,7 @@ void GateIO::stop() {
189188

190189
void GateIO::take_received_tasks(std::vector<TaskPtr>& tasks) {
191190
std::unique_lock<std::mutex> lock(m_tasks_mutex);
192-
for (TaskPtr& task: m_received_tasks) {
191+
for (TaskPtr& task : m_received_tasks) {
193192
m_logger.queue(LogLevel::Debug, "move task id=", task->job_id(), "for processing");
194193
tasks.push_back(std::move(task));
195194
}
@@ -198,7 +197,7 @@ void GateIO::take_received_tasks(std::vector<TaskPtr>& tasks) {
198197

199198
void GateIO::move_tasks_to_send_queue(std::vector<TaskPtr>& tasks) {
200199
std::unique_lock<std::mutex> lock(m_tasks_mutex);
201-
for (TaskPtr& task: tasks) {
200+
for (TaskPtr& task : tasks) {
202201
m_logger.queue(LogLevel::Debug, "move task id=", task->job_id(), "finished", (task->has_error() ? "with error" : "successfully"), task->error(), "to send queue");
203202
m_send_tasks.push_back(std::move(task));
204203
}
@@ -208,7 +207,7 @@ void GateIO::move_tasks_to_send_queue(std::vector<TaskPtr>& tasks) {
208207
void GateIO::start_listening() {
209208
#ifdef ENABLE_CLIENT_ALIVE_TRACKER
210209
std::unique_ptr<ClientAliveTracker> client_alive_tracker_ptr =
211-
std::make_unique<ClientAliveTracker>(std::chrono::milliseconds{5000}, std::chrono::milliseconds{20000});
210+
std::make_unique<ClientAliveTracker>(std::chrono::milliseconds{5000}, std::chrono::milliseconds{20000});
212211
#else
213212
std::unique_ptr<ClientAliveTracker> client_alive_tracker_ptr;
214213
#endif
@@ -232,7 +231,7 @@ void GateIO::start_listening() {
232231
received_message.resize(CHUNK_MAX_BYTES_NUM);
233232

234233
/// comm event loop
235-
while(m_is_running.load()) {
234+
while (m_is_running.load()) {
236235
bool is_communication_problem_detected = false;
237236

238237
if (!client_opt) {
@@ -262,7 +261,7 @@ void GateIO::start_listening() {
262261
// forward telegramBuffer errors
263262
std::vector<std::string> telegram_buffer_errors;
264263
telegram_buff.take_errors(telegram_buffer_errors);
265-
for (const std::string& error: telegram_buffer_errors) {
264+
for (const std::string& error : telegram_buffer_errors) {
266265
m_logger.queue(LogLevel::Info, error);
267266
}
268267

vpr/src/server/gateio.h

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ enum class ActivityStatus : int {
2525
COMMUNICATION_PROBLEM
2626
};
2727

28-
enum class LogLevel: int {
28+
enum class LogLevel : int {
2929
Error,
3030
Info,
3131
Detail,
3232
Debug
3333
};
3434

35-
const std::size_t CHUNK_MAX_BYTES_NUM = 2*1024*1024; // 2Mb
35+
const std::size_t CHUNK_MAX_BYTES_NUM = 2 * 1024 * 1024; // 2Mb
3636

37-
/**
37+
/**
3838
* @brief Helper class aimed to help detecting a client offline.
3939
*
4040
* The ClientAliveTracker is pinged each time there is some activity from the client side.
@@ -44,12 +44,13 @@ const std::size_t CHUNK_MAX_BYTES_NUM = 2*1024*1024; // 2Mb
4444
* and it's time to start accepting new client connections in GateIO.
4545
*/
4646
class ClientAliveTracker {
47-
public:
47+
public:
4848
ClientAliveTracker(const std::chrono::milliseconds& echoIntervalMs, const std::chrono::milliseconds& clientTimeoutMs)
49-
: m_echo_interval_ms(echoIntervalMs), m_client_timeout_ms(clientTimeoutMs) {
49+
: m_echo_interval_ms(echoIntervalMs)
50+
, m_client_timeout_ms(clientTimeoutMs) {
5051
reset();
5152
}
52-
ClientAliveTracker()=default;
53+
ClientAliveTracker() = default;
5354

5455
void on_client_activity() {
5556
m_last_client_activity_time = std::chrono::high_resolution_clock::now();
@@ -62,13 +63,13 @@ class ClientAliveTracker {
6263
bool is_time_to_sent_echo() const {
6364
return (duration_since_last_client_activity_ms() > m_echo_interval_ms) && (durationSinceLastEchoSentMs() > m_echo_interval_ms);
6465
}
65-
bool is_client_timeout() const { return duration_since_last_client_activity_ms() > m_client_timeout_ms; }
66+
bool is_client_timeout() const { return duration_since_last_client_activity_ms() > m_client_timeout_ms; }
6667

6768
void reset() {
6869
on_client_activity();
6970
}
7071

71-
private:
72+
private:
7273
std::chrono::high_resolution_clock::time_point m_last_client_activity_time;
7374
std::chrono::high_resolution_clock::time_point m_last_echo_sent_time;
7475
std::chrono::milliseconds m_echo_interval_ms;
@@ -84,10 +85,8 @@ class ClientAliveTracker {
8485
}
8586
};
8687

87-
88-
8988
class TLogger {
90-
public:
89+
public:
9190
TLogger() {
9291
m_log_level = static_cast<int>(LogLevel::Info);
9392
}
@@ -113,7 +112,7 @@ class TLogger {
113112
}
114113
}
115114

116-
private:
115+
private:
117116
std::stringstream m_log_stream;
118117
std::mutex m_log_stream_mutex;
119118
std::atomic<int> m_log_level;
@@ -135,12 +134,11 @@ class TLogger {
135134
* and responsiveness of the application.
136135
* - GateIO is not started automatically upon creation, you have to use the 'start' method with the port number.
137136
* - The socket is initialized in a non-blocking mode to function properly in a multithreaded environment.
138-
*/
139-
class GateIO
140-
{
137+
*/
138+
class GateIO {
141139
const int LOOP_INTERVAL_MS = 100;
142140

143-
public:
141+
public:
144142
/**
145143
* @brief Default constructor for GateIO.
146144
*/
@@ -154,10 +152,10 @@ class GateIO
154152
GateIO& operator=(GateIO&&) = delete;
155153

156154
/**
157-
* @brief Returns a bool indicating whether or not the port listening process is currently running.
158-
*
159-
* @return True if the port listening process is running, false otherwise.
160-
*/
155+
* @brief Returns a bool indicating whether or not the port listening process is currently running.
156+
*
157+
* @return True if the port listening process is running, false otherwise.
158+
*/
161159
bool is_running() const { return m_is_running.load(); }
162160

163161
/**
@@ -178,7 +176,7 @@ class GateIO
178176
* remains empty after the operation.
179177
*
180178
* @param tasks A reference to a vector containing the tasks to be moved to the send queue.
181-
*/
179+
*/
182180
void move_tasks_to_send_queue(std::vector<TaskPtr>& tasks);
183181

184182
/**
@@ -187,7 +185,7 @@ class GateIO
187185
* @note Must be called from the main thread since it's invoke std::cout.
188186
* Calling this method from other threads may result in unexpected behavior.
189187
*/
190-
void print_logs();
188+
void print_logs();
191189

192190
/**
193191
* @brief Starts the server on the specified port number.
@@ -210,16 +208,16 @@ class GateIO
210208
*/
211209
void stop();
212210

213-
private:
211+
private:
214212
int m_port_num = -1;
215213

216214
std::atomic<bool> m_is_running; // is true when started
217215

218216
std::thread m_thread; // thread to execute socket IO work
219217

220-
std::mutex m_tasks_mutex; // we used single mutex to guard both vectors m_received_tasks and m_sendTasks
218+
std::mutex m_tasks_mutex; // we used single mutex to guard both vectors m_received_tasks and m_sendTasks
221219
std::vector<TaskPtr> m_received_tasks; // tasks from client (requests)
222-
std::vector<TaskPtr> m_send_tasks; // tasks to client (responses)
220+
std::vector<TaskPtr> m_send_tasks; // tasks to client (responses)
223221

224222
TLogger m_logger;
225223

@@ -231,4 +229,3 @@ class GateIO
231229
#endif /* NO_SERVER */
232230

233231
#endif /* GATEIO_H */
234-

0 commit comments

Comments
 (0)