Skip to content

Commit aae2094

Browse files
authored
Merge pull request #4 from ReCodEx/modernization
Much better code
2 parents 60d2a4a + 831108b commit aae2094

39 files changed

+306
-285
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ set(SOURCE_FILES
3535
src/helpers/logger.cpp
3636
src/helpers/curl.h
3737
src/helpers/curl.cpp
38+
src/worker.h
3839
src/worker.cpp
3940
src/notifier/status_notifier.h
4041
src/notifier/http_status_notifier.h
4142
src/notifier/http_status_notifier.cpp
4243
src/notifier/empty_status_notifier.h
44+
src/reactor/reactor.h
4345
src/reactor/reactor.cpp
4446
src/reactor/socket_wrapper_base.cpp
4547
src/reactor/socket_wrapper_base.h
48+
src/reactor/message_container.h
4649
src/reactor/message_container.cpp
4750
src/reactor/handler_interface.h
4851
src/reactor/router_socket_wrapper.h

recodex-broker.spec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
%define name recodex-broker
22
%define short_name broker
3-
%define version 1.0.0
4-
%define unmangled_version 1bd664ddc7ba30e7666ce0737f5a714ecbce9ae8
5-
%define release 6
3+
%define version 1.2.1
4+
%define unmangled_version 60d2a4ae569df9780f85446969718fa27193dd6c
5+
%define release 1
66

77
%define spdlog_name spdlog
88
%define spdlog_version 0.13.0

src/broker_core.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void broker_core::load_config()
6868
}
6969
}
7070

71-
void broker_core::force_exit(std::string msg)
71+
void broker_core::force_exit(const std::string &msg)
7272
{
7373
// write to log
7474
if (msg != "") {
@@ -78,7 +78,7 @@ void broker_core::force_exit(std::string msg)
7878
std::cerr << msg << std::endl;
7979
}
8080

81-
exit(1);
81+
std::exit(1);
8282
}
8383

8484
void broker_core::log_init()

src/broker_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class broker_core
9191
* Exit whole application with return code 1.
9292
* @param msg String which is copied to stderr and logger if initialized (emerg level).
9393
*/
94-
void force_exit(std::string msg = "");
94+
[[noreturn]] void force_exit(const std::string &msg = "");
9595

9696
/**
9797
* Parse command line arguments given in constructor.

src/config/broker_config.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "broker_config.h"
22

3-
broker_config::broker_config()
4-
{
5-
}
63

74
broker_config::broker_config(const YAML::Node &config)
85
{
@@ -17,7 +14,7 @@ broker_config::broker_config(const YAML::Node &config)
1714
client_address_ = config["clients"]["address"].as<std::string>();
1815
} // no throw... can be omitted
1916
if (config["clients"]["port"] && config["clients"]["port"].IsScalar()) {
20-
client_port_ = config["clients"]["port"].as<uint16_t>();
17+
client_port_ = config["clients"]["port"].as<std::uint16_t>();
2118
} // no throw... can be omitted
2219
}
2320

@@ -27,16 +24,16 @@ broker_config::broker_config(const YAML::Node &config)
2724
worker_address_ = config["workers"]["address"].as<std::string>();
2825
} // no throw... can be omitted
2926
if (config["workers"]["port"] && config["workers"]["port"].IsScalar()) {
30-
worker_port_ = config["workers"]["port"].as<uint16_t>();
27+
worker_port_ = config["workers"]["port"].as<std::uint16_t>();
3128
} // no throw... can be omitted
3229
if (config["workers"]["max_liveness"] && config["workers"]["max_liveness"].IsScalar()) {
33-
max_worker_liveness_ = config["workers"]["max_liveness"].as<size_t>();
30+
max_worker_liveness_ = config["workers"]["max_liveness"].as<std::size_t>();
3431
} // no throw... can be omitted
3532
if (config["workers"]["max_request_failures"] && config["workers"]["max_request_failures"].IsScalar()) {
36-
max_request_failures_ = config["workers"]["max_request_failures"].as<size_t>();
33+
max_request_failures_ = config["workers"]["max_request_failures"].as<std::size_t>();
3734
} // no throw... can be omitted
3835
if (config["workers"]["ping_interval"] && config["workers"]["ping_interval"].IsScalar()) {
39-
worker_ping_interval_ = std::chrono::milliseconds(config["workers"]["ping_interval"].as<size_t>());
36+
worker_ping_interval_ = std::chrono::milliseconds(config["workers"]["ping_interval"].as<std::size_t>());
4037
} // no throw... can be omitted
4138
}
4239

@@ -46,7 +43,7 @@ broker_config::broker_config(const YAML::Node &config)
4643
monitor_address_ = config["monitor"]["address"].as<std::string>();
4744
} // no throw... can be omitted
4845
if (config["monitor"]["port"] && config["monitor"]["port"].IsScalar()) {
49-
monitor_port_ = config["monitor"]["port"].as<uint16_t>();
46+
monitor_port_ = config["monitor"]["port"].as<std::uint16_t>();
5047
} // no throw... can be omitted
5148
}
5249

@@ -56,7 +53,7 @@ broker_config::broker_config(const YAML::Node &config)
5653
notifier_config_.address = config["notifier"]["address"].as<std::string>();
5754
} // no throw... can be omitted
5855
if (config["notifier"]["port"] && config["notifier"]["port"].IsScalar()) {
59-
notifier_config_.port = config["notifier"]["port"].as<uint16_t>();
56+
notifier_config_.port = config["notifier"]["port"].as<std::uint16_t>();
6057
} // no throw... can be omitted
6158
if (config["notifier"]["username"] && config["notifier"]["username"].IsScalar()) {
6259
notifier_config_.username = config["notifier"]["username"].as<std::string>();
@@ -77,10 +74,10 @@ broker_config::broker_config(const YAML::Node &config)
7774
log_config_.log_level = config["logger"]["level"].as<std::string>();
7875
} // no throw... can be omitted
7976
if (config["logger"]["max-size"] && config["logger"]["max-size"].IsScalar()) {
80-
log_config_.log_file_size = config["logger"]["max-size"].as<size_t>();
77+
log_config_.log_file_size = config["logger"]["max-size"].as<std::size_t>();
8178
} // no throw... can be omitted
8279
if (config["logger"]["rotations"] && config["logger"]["rotations"].IsScalar()) {
83-
log_config_.log_files_count = config["logger"]["rotations"].as<size_t>();
80+
log_config_.log_files_count = config["logger"]["rotations"].as<std::size_t>();
8481
} // no throw... can be omitted
8582
} // no throw... can be omitted
8683
} catch (YAML::Exception &ex) {
@@ -93,7 +90,7 @@ const std::string &broker_config::get_client_address() const
9390
return client_address_;
9491
}
9592

96-
uint16_t broker_config::get_client_port() const
93+
std::uint16_t broker_config::get_client_port() const
9794
{
9895
return client_port_;
9996
}
@@ -103,7 +100,7 @@ const std::string &broker_config::get_worker_address() const
103100
return worker_address_;
104101
}
105102

106-
uint16_t broker_config::get_worker_port() const
103+
std::uint16_t broker_config::get_worker_port() const
107104
{
108105
return worker_port_;
109106
}
@@ -113,12 +110,12 @@ const std::string &broker_config::get_monitor_address() const
113110
return monitor_address_;
114111
}
115112

116-
uint16_t broker_config::get_monitor_port() const
113+
std::uint16_t broker_config::get_monitor_port() const
117114
{
118115
return monitor_port_;
119116
}
120117

121-
size_t broker_config::get_max_worker_liveness() const
118+
std::size_t broker_config::get_max_worker_liveness() const
122119
{
123120
return max_worker_liveness_;
124121
}
@@ -138,7 +135,11 @@ const notifier_config &broker_config::get_notifier_config() const
138135
return notifier_config_;
139136
}
140137

141-
size_t broker_config::get_max_request_failures() const
138+
std::size_t broker_config::get_max_request_failures() const
142139
{
143140
return max_request_failures_;
144141
}
142+
143+
config_error::config_error(const std::string &msg) : std::runtime_error(msg)
144+
{
145+
}

src/config/broker_config.h

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RECODEX_BROKER_CONFIG_H
22
#define RECODEX_BROKER_CONFIG_H
33

4+
#include <cstdint>
45
#include <iostream>
56
#include <map>
67
#include <string>
@@ -22,12 +23,16 @@ class broker_config
2223
{
2324
public:
2425
/** A default constructor */
25-
broker_config();
26+
broker_config() = default;
2627
/**
2728
* A constructor that loads the configuration from a YAML document.
2829
* @param config The input document.
2930
*/
3031
broker_config(const YAML::Node &config);
32+
/**
33+
* Destructor
34+
*/
35+
virtual ~broker_config() = default;
3136
/**
3237
* Get IP address for client connections (from frontend).
3338
* @return Broker's IP address for client connections.
@@ -37,7 +42,7 @@ class broker_config
3742
* Get the port to listen for incoming tasks.
3843
* @return Broker's port for client connections.
3944
*/
40-
virtual uint16_t get_client_port() const;
45+
virtual std::uint16_t get_client_port() const;
4146
/**
4247
* Get IP address for worker connections.
4348
* @return Broker's IP address for worker connections.
@@ -47,7 +52,7 @@ class broker_config
4752
* Get the port for communication with workers.
4853
* @return Broker's port for worker connections.
4954
*/
50-
virtual uint16_t get_worker_port() const;
55+
virtual std::uint16_t get_worker_port() const;
5156
/**
5257
* Get IP address for monitor connections.
5358
* @return Broker's IP address for monitor connections.
@@ -57,17 +62,17 @@ class broker_config
5762
* Get the port for communication with monitor.
5863
* @return Broker's port for monitor connections.
5964
*/
60-
virtual uint16_t get_monitor_port() const;
65+
virtual std::uint16_t get_monitor_port() const;
6166
/**
6267
* Get the maximum (i.e. initial) liveness of a worker.
6368
* @return Maximum liveness of worker.
6469
*/
65-
virtual size_t get_max_worker_liveness() const;
70+
virtual std::size_t get_max_worker_liveness() const;
6671
/**
6772
* Get the amount of times a request can fail before it's cancelled
6873
* @return Maximum request failure count
6974
*/
70-
virtual size_t get_max_request_failures() const;
75+
virtual std::size_t get_max_request_failures() const;
7176
/**
7277
* Get the time (in milliseconds) expected to pass between pings from the worker.
7378
* @return Interval between two concurrent pings.
@@ -87,23 +92,23 @@ class broker_config
8792
private:
8893
/** Client socket address (from frontend) */
8994
std::string client_address_ = "*"; // '*' is any address
90-
/** Client socket port (from frontend) */
91-
uint16_t client_port_ = 0;
9295
/** Server socket address (to workers) */
9396
std::string worker_address_ = "*"; // '*' is any address
94-
/** Server socket port (to workers) */
95-
uint16_t worker_port_ = 0;
9697
/** Monitor socket address */
9798
std::string monitor_address_ = "127.0.0.1";
99+
/** Client socket port (from frontend) */
100+
std::uint16_t client_port_ = 0;
101+
/** Server socket port (to workers) */
102+
std::uint16_t worker_port_ = 0;
98103
/** Monitor socket port */
99-
uint16_t monitor_port_ = 7894;
104+
std::uint16_t monitor_port_ = 7894;
100105
/**
101106
* Maximum (initial) liveness of a worker
102107
* (the amount of pings the worker can miss before it's considered dead)
103108
*/
104-
size_t max_worker_liveness_ = 4;
109+
std::size_t max_worker_liveness_ = 4;
105110
/** The amount of times a request can fail before it's cancelled */
106-
size_t max_request_failures_ = 3;
111+
std::size_t max_request_failures_ = 3;
107112
/** Time (in milliseconds) expected to pass between pings from the worker */
108113
std::chrono::milliseconds worker_ping_interval_ = std::chrono::milliseconds(1000);
109114
/** Configuration of logger */
@@ -119,13 +124,14 @@ class broker_config
119124
class config_error : public std::runtime_error
120125
{
121126
public:
127+
/** Destructor */
128+
~config_error() override = default;
129+
122130
/**
123131
* Construction with message returned with @a what method.
124132
* @param msg description of exception circumstances
125133
*/
126-
explicit config_error(const std::string &msg) : std::runtime_error(msg)
127-
{
128-
}
134+
explicit config_error(const std::string &msg);
129135
};
130136

131137
#endif // RECODEX_BROKER_CONFIG_H

src/config/log_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ struct log_config {
2929
/**
3030
* File size of one rotation of log file.
3131
*/
32-
int log_file_size = 1024 * 1024;
32+
std::size_t log_file_size = 1024 * 1024;
3333
/**
3434
* Number of rotations which will be kept saved.
3535
*/
36-
int log_files_count = 3;
36+
std::size_t log_files_count = 3;
3737

3838
/**
3939
* Equality operator on @ref log_config structures.

src/config/notifier_config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RECODEX_NOTIFIER_CONFIG_H
22
#define RECODEX_NOTIFIER_CONFIG_H
33

4+
#include <cstdint>
45
#include <string>
56

67

@@ -16,7 +17,7 @@ struct notifier_config {
1617
/**
1718
* Port on which frontend runs.
1819
*/
19-
uint16_t port;
20+
std::uint16_t port;
2021

2122
/**
2223
* Username which is used in HTTP authentication.

0 commit comments

Comments
 (0)