SNode.C
Loading...
Searching...
No Matches
net::config::ConfigPhysicalSocket Class Reference

#include <ConfigPhysicalSocket.h>

Inheritance diagram for net::config::ConfigPhysicalSocket:
Collaboration diagram for net::config::ConfigPhysicalSocket:

Public Member Functions

const std::map< int, std::map< int, const net::phy::PhysicalSocketOption > > & getSocketOptions ()
 
ConfigPhysicalSocketaddSocketOption (int optLevel, int optName, int optValue)
 
ConfigPhysicalSocketaddSocketOption (int optLevel, int optName, const std::string &optValue)
 
ConfigPhysicalSocketaddSocketOption (int optLevel, int optName, const std::vector< char > &optValue)
 
ConfigPhysicalSocketremoveSocketOption (int optLevel, int optName)
 
ConfigPhysicalSocketsetRetry (bool retry=true)
 
bool getRetry () const
 
ConfigPhysicalSocketsetRetryOnFatal (bool retry=true)
 
bool getRetryOnFatal () const
 
ConfigPhysicalSocketsetRetryTimeout (double sec)
 
double getRetryTimeout () const
 
ConfigPhysicalSocketsetRetryTries (unsigned int tries=0)
 
unsigned int getRetryTries () const
 
ConfigPhysicalSocketsetRetryBase (double base)
 
double getRetryBase () const
 
ConfigPhysicalSocketsetRetryLimit (unsigned int limit)
 
unsigned int getRetryLimit () const
 
ConfigPhysicalSocketsetRetryJitter (double percent)
 
double getRetryJitter () const
 

Protected Member Functions

 ConfigPhysicalSocket (ConfigInstance *instance)
 
CLI::Option * addSocketOption (const std::string &name, int optLevel, int optName, const std::string &description, const std::string &typeName, const std::string &defaultValue, const CLI::Validator &validator)
 
- Protected Member Functions inherited from net::config::ConfigSection
 ConfigSection (ConfigInstance *instance, const std::string &name, const std::string &description)
 
 ConfigSection (const ConfigSection &)=delete
 
 ConfigSection (ConfigSection &&)=delete
 
ConfigSectionoperator= (const ConfigSection &)=delete
 
ConfigSectionoperator= (ConfigSection &&)=delete
 
CLI::Option * addOption (const std::string &name, const std::string &description)
 
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName)
 
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &additionalValidator)
 
template<typename ValueTypeT >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue)
 
template<typename ValueTypeT >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator)
 
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName)
 
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, const CLI::Validator &additionalValidator)
 
template<typename ValueTypeT >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue)
 
template<typename ValueTypeT >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueTypeT defaultValue, const CLI::Validator &additionalValidator)
 
CLI::Option * addFlagFunction (const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const std::string &defaultValue)
 
CLI::Option * addFlagFunction (const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const std::string &defaultValue, const CLI::Validator &validator)
 
void required (CLI::Option *opt, bool req=true)
 
bool required () const
 
template<typename ValueType >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue)
 
template<typename ValueType >
CLI::Option * addOption (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue, const CLI::Validator &additionalValidator)
 
template<typename ValueType >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue)
 
template<typename ValueType >
CLI::Option * addFlag (const std::string &name, const std::string &description, const std::string &typeName, ValueType defaultValue, const CLI::Validator &additionalValidator)
 

Private Attributes

CLI::Option * retryOpt = nullptr
 
CLI::Option * retryOnFatalOpt = nullptr
 
CLI::Option * retryTriesOpt = nullptr
 
CLI::Option * retryTimeoutOpt = nullptr
 
CLI::Option * retryBaseOpt = nullptr
 
CLI::Option * retryLimitOpt = nullptr
 
CLI::Option * retryJitterOpt = nullptr
 
std::map< int, std::map< int, const net::phy::PhysicalSocketOption > > socketOptionsMapMap
 

Additional Inherited Members

- Protected Attributes inherited from net::config::ConfigSection
CLI::App * section = nullptr
 

Detailed Description

Definition at line 66 of file ConfigPhysicalSocket.h.

Constructor & Destructor Documentation

◆ ConfigPhysicalSocket()

net::config::ConfigPhysicalSocket::ConfigPhysicalSocket ( ConfigInstance instance)
explicitprotected

Definition at line 59 of file ConfigPhysicalSocket.cpp.

60 : ConfigSection(instance, "socket", "Configuration of socket behavior") {
61 retryOpt = addFlag( //
62 "--retry{true}",
63 "Automatically retry listen|connect",
64 "bool",
65 XSTR(RETRY),
66 CLI::IsMember({"true", "false"}));
67
69 "--retry-on-fatal{true}",
70 [this]() {
71 if (retryOnFatalOpt->as<bool>() && !retryOpt->as<bool>()) {
72 throw CLI::RequiresError(retryOnFatalOpt->get_name(), retryOpt->get_name().append("=true"));
73 }
74 },
75 "Retry also on fatal errors",
76 "bool",
77 XSTR(RETRY_ON_FATAL),
78 CLI::IsMember({"true", "false"}));
80
82 "--retry-timeout",
83 "Timeout of the retry timer",
84 "sec",
85 RETRY_TIMEOUT,
86 CLI::NonNegativeNumber);
88
90 "--retry-tries",
91 "Number of retry attempts before giving up (0 = unlimited)",
92 "tries",
93 RETRY_TRIES,
94 CLI::TypeValidator<unsigned int>());
95 retryTriesOpt->needs(retryOpt);
96
98 "--retry-base",
99 "Base of exponential backoff",
100 "base",
101 RETRY_BASE,
102 CLI::PositiveNumber);
103 retryBaseOpt->needs(retryOpt);
104
106 "--retry-jitter",
107 "Maximum jitter in percent to apply randomly to calculated retry timeout (0 to disable)",
108 "jitter",
109 RETRY_JITTER,
110 CLI::Range(0., 100.));
111 retryJitterOpt->needs(retryOpt);
112
114 "--retry-limit",
115 "Upper limit in seconds of retry timeout (0 for infinite)",
116 "sec",
117 RETRY_LIMIT,
118 CLI::NonNegativeNumber);
119 retryLimitOpt->needs(retryOpt);
120 }
#define XSTR(s)
ConfigSection(ConfigInstance *instance, const std::string &name, const std::string &description)
CLI::Option * addOption(const std::string &name, const std::string &description)
CLI::Option * addFlagFunction(const std::string &name, const std::function< void()> &callback, const std::string &description, const std::string &typeName, const std::string &defaultValue)
CLI::Option * addFlag(const std::string &name, const std::string &description, const std::string &typeName)

References net::config::ConfigSection::addFlag(), net::config::ConfigSection::addFlagFunction(), net::config::ConfigSection::ConfigSection(), retryBaseOpt, retryJitterOpt, retryLimitOpt, retryOnFatalOpt, retryOpt, retryTimeoutOpt, and retryTriesOpt.

Referenced by net::config::ConfigPhysicalSocketClient::ConfigPhysicalSocketClient(), and net::config::ConfigPhysicalSocketServer::ConfigPhysicalSocketServer().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ addSocketOption() [1/4]

CLI::Option * net::config::ConfigPhysicalSocket::addSocketOption ( const std::string &  name,
int  optLevel,
int  optName,
const std::string &  description,
const std::string &  typeName,
const std::string &  defaultValue,
const CLI::Validator &  validator 
)
protected

Definition at line 126 of file ConfigPhysicalSocket.cpp.

132 {
133 return addFlagFunction(
134 name,
135 [this, strippedName = name.substr(0, name.find('{')), optLevel, optName]() {
136 try {
137 try {
138 if (section->get_option(strippedName)->as<bool>()) {
139 socketOptionsMapMap[optLevel].emplace(optName, net::phy::PhysicalSocketOption(optLevel, optName, 1));
140 } else {
141 socketOptionsMapMap[optLevel].emplace(optName, net::phy::PhysicalSocketOption(optLevel, optName, 0));
142 }
143 } catch ([[maybe_unused]] CLI::ConversionError& err) {
144 if (socketOptionsMapMap.contains(optLevel)) {
145 socketOptionsMapMap[optLevel].erase(optName);
146 if (socketOptionsMapMap[optLevel].empty()) {
147 socketOptionsMapMap.erase(optLevel);
148 }
149 }
150 }
151 } catch (CLI::OptionNotFound& err) {
152 LOG(ERROR) << err.what();
153 }
154 },
155 description,
156 typeName,
157 defaultValue,
158 validator)
159 ->force_callback();
160 }

References net::config::ConfigSection::addFlagFunction(), net::phy::PhysicalSocketOption::PhysicalSocketOption(), net::config::ConfigSection::section, and socketOptionsMapMap.

Referenced by net::in::stream::config::ConfigSocketClient::ConfigSocketClient(), net::in6::stream::config::ConfigSocketClient::ConfigSocketClient(), net::in::stream::config::ConfigSocketServer::ConfigSocketServer(), and net::in6::stream::config::ConfigSocketServer::ConfigSocketServer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addSocketOption() [2/4]

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::addSocketOption ( int  optLevel,
int  optName,
const std::string &  optValue 
)

Definition at line 168 of file ConfigPhysicalSocket.cpp.

168 {
169 socketOptionsMapMap[optLevel].emplace(optName, net::phy::PhysicalSocketOption(optLevel, optName, optValue));
170
171 return *this;
172 }
std::map< int, std::map< int, const net::phy::PhysicalSocketOption > > socketOptionsMapMap

References net::phy::PhysicalSocketOption::PhysicalSocketOption(), and socketOptionsMapMap.

Here is the call graph for this function:

◆ addSocketOption() [3/4]

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::addSocketOption ( int  optLevel,
int  optName,
const std::vector< char > &  optValue 
)

Definition at line 174 of file ConfigPhysicalSocket.cpp.

174 {
175 socketOptionsMapMap[optLevel].emplace(optName, net::phy::PhysicalSocketOption(optLevel, optName, optValue));
176
177 return *this;
178 }

References net::phy::PhysicalSocketOption::PhysicalSocketOption(), and socketOptionsMapMap.

Here is the call graph for this function:

◆ addSocketOption() [4/4]

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::addSocketOption ( int  optLevel,
int  optName,
int  optValue 
)

◆ getRetry()

bool net::config::ConfigPhysicalSocket::getRetry ( ) const

Definition at line 213 of file ConfigPhysicalSocket.cpp.

213 {
214 return retryOpt->as<bool>();
215 }

References retryOpt.

◆ getRetryBase()

double net::config::ConfigPhysicalSocket::getRetryBase ( ) const

Definition at line 261 of file ConfigPhysicalSocket.cpp.

261 {
262 return retryBaseOpt->as<double>();
263 }

References retryBaseOpt.

◆ getRetryJitter()

double net::config::ConfigPhysicalSocket::getRetryJitter ( ) const

Definition at line 285 of file ConfigPhysicalSocket.cpp.

285 {
286 return retryJitterOpt->as<double>();
287 }

References retryJitterOpt.

◆ getRetryLimit()

unsigned int net::config::ConfigPhysicalSocket::getRetryLimit ( ) const

Definition at line 273 of file ConfigPhysicalSocket.cpp.

273 {
274 return retryLimitOpt->as<unsigned int>();
275 }

References retryLimitOpt.

◆ getRetryOnFatal()

bool net::config::ConfigPhysicalSocket::getRetryOnFatal ( ) const

Definition at line 225 of file ConfigPhysicalSocket.cpp.

225 {
226 return retryOnFatalOpt->as<bool>();
227 }

References retryOnFatalOpt.

◆ getRetryTimeout()

double net::config::ConfigPhysicalSocket::getRetryTimeout ( ) const

Definition at line 237 of file ConfigPhysicalSocket.cpp.

237 {
238 return retryTimeoutOpt->as<double>();
239 }

References retryTimeoutOpt.

◆ getRetryTries()

unsigned int net::config::ConfigPhysicalSocket::getRetryTries ( ) const

Definition at line 249 of file ConfigPhysicalSocket.cpp.

249 {
250 return retryTriesOpt->as<unsigned int>();
251 }

References retryTriesOpt.

◆ getSocketOptions()

const std::map< int, std::map< int, const net::phy::PhysicalSocketOption > > & net::config::ConfigPhysicalSocket::getSocketOptions ( )

Definition at line 122 of file ConfigPhysicalSocket.cpp.

122 {
123 return socketOptionsMapMap;
124 }

References socketOptionsMapMap.

◆ removeSocketOption()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::removeSocketOption ( int  optLevel,
int  optName 
)

Definition at line 180 of file ConfigPhysicalSocket.cpp.

180 {
181 socketOptionsMapMap[optLevel].erase(optName);
182 if (socketOptionsMapMap[optLevel].empty()) {
183 socketOptionsMapMap.erase(optLevel);
184 }
185
186 return *this;
187 }

References socketOptionsMapMap.

◆ setRetry()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetry ( bool  retry = true)

Definition at line 189 of file ConfigPhysicalSocket.cpp.

189 {
190 retryOpt //
191 ->default_val(retry ? "true" : "false")
192 ->clear();
193
194 if (retry) {
195 retryLimitOpt->remove_needs(retryOpt);
196 retryJitterOpt->remove_needs(retryOpt);
197 retryBaseOpt->remove_needs(retryOpt);
198 retryTriesOpt->remove_needs(retryOpt);
199 retryTimeoutOpt->remove_needs(retryOpt);
200 retryOnFatalOpt->remove_needs(retryOpt);
201 } else {
202 retryLimitOpt->needs(retryOpt);
203 retryJitterOpt->needs(retryOpt);
204 retryBaseOpt->needs(retryOpt);
205 retryTriesOpt->needs(retryOpt);
208 }
209
210 return *this;
211 }

References retryBaseOpt, retryJitterOpt, retryLimitOpt, retryOnFatalOpt, retryOpt, retryTimeoutOpt, and retryTriesOpt.

◆ setRetryBase()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryBase ( double  base)

Definition at line 253 of file ConfigPhysicalSocket.cpp.

253 {
254 retryBaseOpt //
255 ->default_val(base)
256 ->clear();
257
258 return *this;
259 }

References retryBaseOpt.

◆ setRetryJitter()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryJitter ( double  percent)

Definition at line 277 of file ConfigPhysicalSocket.cpp.

277 {
279 ->default_val(percent)
280 ->clear();
281
282 return *this;
283 }

References retryJitterOpt.

◆ setRetryLimit()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryLimit ( unsigned int  limit)

Definition at line 265 of file ConfigPhysicalSocket.cpp.

265 {
267 ->default_val(limit)
268 ->clear();
269
270 return *this;
271 }

References retryLimitOpt.

◆ setRetryOnFatal()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryOnFatal ( bool  retry = true)

Definition at line 217 of file ConfigPhysicalSocket.cpp.

217 {
219 ->default_val(retry ? "true" : "false")
220 ->clear();
221
222 return *this;
223 }

References retryOnFatalOpt.

◆ setRetryTimeout()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryTimeout ( double  sec)

Definition at line 229 of file ConfigPhysicalSocket.cpp.

229 {
231 ->default_val(sec)
232 ->clear();
233
234 return *this;
235 }

References retryTimeoutOpt.

◆ setRetryTries()

ConfigPhysicalSocket & net::config::ConfigPhysicalSocket::setRetryTries ( unsigned int  tries = 0)

Definition at line 241 of file ConfigPhysicalSocket.cpp.

241 {
243 ->default_val(tries)
244 ->clear();
245
246 return *this;
247 }

References retryTriesOpt.

Member Data Documentation

◆ retryBaseOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryBaseOpt = nullptr
private

Definition at line 114 of file ConfigPhysicalSocket.h.

Referenced by ConfigPhysicalSocket(), getRetryBase(), setRetry(), and setRetryBase().

◆ retryJitterOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryJitterOpt = nullptr
private

◆ retryLimitOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryLimitOpt = nullptr
private

◆ retryOnFatalOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryOnFatalOpt = nullptr
private

◆ retryOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryOpt = nullptr
private

Definition at line 110 of file ConfigPhysicalSocket.h.

Referenced by ConfigPhysicalSocket(), getRetry(), and setRetry().

◆ retryTimeoutOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryTimeoutOpt = nullptr
private

◆ retryTriesOpt

CLI::Option* net::config::ConfigPhysicalSocket::retryTriesOpt = nullptr
private

◆ socketOptionsMapMap

std::map<int, std::map<int, const net::phy::PhysicalSocketOption> > net::config::ConfigPhysicalSocket::socketOptionsMapMap
private

The documentation for this class was generated from the following files: