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, 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, 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 addSocketOption(optLevel, optName, section->get_option(strippedName)->as<bool>() ? 1 : 0);
140 } else {
141 addSocketOption(optLevel, optName, 0);
142 }
143 } catch ([[maybe_unused]] CLI::ConversionError& err) {
144 removeSocketOption(optLevel, optName);
145 }
146 } catch (CLI::OptionNotFound& err) {
147 LOG(ERROR) << err.what();
148 }
149 },
150 description,
151 typeName,
152 defaultValue,
153 validator)
154 ->force_callback();
155 }

References net::config::ConfigSection::addFlagFunction(), addSocketOption(), removeSocketOption(), and net::config::ConfigSection::section.

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 163 of file ConfigPhysicalSocket.cpp.

163 {
164 socketOptionsMapMap[optLevel][optName] = net::phy::PhysicalSocketOption(optLevel, optName, optValue);
165
166 return *this;
167 }
std::map< int, std::map< int, 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 169 of file ConfigPhysicalSocket.cpp.

169 {
170 socketOptionsMapMap[optLevel][optName] = net::phy::PhysicalSocketOption(optLevel, optName, optValue);
171
172 return *this;
173 }

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 208 of file ConfigPhysicalSocket.cpp.

208 {
209 return retryOpt->as<bool>();
210 }

References retryOpt.

◆ getRetryBase()

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

Definition at line 256 of file ConfigPhysicalSocket.cpp.

256 {
257 return retryBaseOpt->as<double>();
258 }

References retryBaseOpt.

◆ getRetryJitter()

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

Definition at line 280 of file ConfigPhysicalSocket.cpp.

280 {
281 return retryJitterOpt->as<double>();
282 }

References retryJitterOpt.

◆ getRetryLimit()

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

Definition at line 268 of file ConfigPhysicalSocket.cpp.

268 {
269 return retryLimitOpt->as<unsigned int>();
270 }

References retryLimitOpt.

◆ getRetryOnFatal()

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

Definition at line 220 of file ConfigPhysicalSocket.cpp.

220 {
221 return retryOnFatalOpt->as<bool>();
222 }

References retryOnFatalOpt.

◆ getRetryTimeout()

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

Definition at line 232 of file ConfigPhysicalSocket.cpp.

232 {
233 return retryTimeoutOpt->as<double>();
234 }

References retryTimeoutOpt.

◆ getRetryTries()

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

Definition at line 244 of file ConfigPhysicalSocket.cpp.

244 {
245 return retryTriesOpt->as<unsigned int>();
246 }

References retryTriesOpt.

◆ getSocketOptions()

const std::map< int, std::map< int, 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 175 of file ConfigPhysicalSocket.cpp.

175 {
176 socketOptionsMapMap[optLevel].erase(optName);
177 if (socketOptionsMapMap[optLevel].empty()) {
178 socketOptionsMapMap.erase(optLevel);
179 }
180
181 return *this;
182 }

References socketOptionsMapMap.

Referenced by addSocketOption().

Here is the caller graph for this function:

◆ setRetry()

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

Definition at line 184 of file ConfigPhysicalSocket.cpp.

184 {
185 retryOpt //
186 ->default_val(retry ? "true" : "false")
187 ->clear();
188
189 if (retry) {
190 retryLimitOpt->remove_needs(retryOpt);
191 retryJitterOpt->remove_needs(retryOpt);
192 retryBaseOpt->remove_needs(retryOpt);
193 retryTriesOpt->remove_needs(retryOpt);
194 retryTimeoutOpt->remove_needs(retryOpt);
195 retryOnFatalOpt->remove_needs(retryOpt);
196 } else {
197 retryLimitOpt->needs(retryOpt);
198 retryJitterOpt->needs(retryOpt);
199 retryBaseOpt->needs(retryOpt);
200 retryTriesOpt->needs(retryOpt);
203 }
204
205 return *this;
206 }

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

◆ setRetryBase()

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

Definition at line 248 of file ConfigPhysicalSocket.cpp.

248 {
249 retryBaseOpt //
250 ->default_val(base)
251 ->clear();
252
253 return *this;
254 }

References retryBaseOpt.

◆ setRetryJitter()

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

Definition at line 272 of file ConfigPhysicalSocket.cpp.

272 {
274 ->default_val(percent)
275 ->clear();
276
277 return *this;
278 }

References retryJitterOpt.

◆ setRetryLimit()

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

Definition at line 260 of file ConfigPhysicalSocket.cpp.

260 {
262 ->default_val(limit)
263 ->clear();
264
265 return *this;
266 }

References retryLimitOpt.

◆ setRetryOnFatal()

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

Definition at line 212 of file ConfigPhysicalSocket.cpp.

212 {
214 ->default_val(retry ? "true" : "false")
215 ->clear();
216
217 return *this;
218 }

References retryOnFatalOpt.

◆ setRetryTimeout()

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

Definition at line 224 of file ConfigPhysicalSocket.cpp.

224 {
226 ->default_val(sec)
227 ->clear();
228
229 return *this;
230 }

References retryTimeoutOpt.

◆ setRetryTries()

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

Definition at line 236 of file ConfigPhysicalSocket.cpp.

236 {
238 ->default_val(tries)
239 ->clear();
240
241 return *this;
242 }

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, net::phy::PhysicalSocketOption> > net::config::ConfigPhysicalSocket::socketOptionsMapMap
private

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