Skip to content

Commit 842bf9b

Browse files
committed
Implement src/dst address pinting in pcapslice. Remove deprecated throw.
1 parent 1d37a00 commit 842bf9b

17 files changed

+141
-80
lines changed

.idea/emacs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/rebar.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/utxx/config_validator.hpp

+11-14
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,15 @@ namespace config {
351351
const variant_tree_base& def(
352352
const tree_path& a_path,
353353
const tree_path& a_root_path = tree_path()
354-
) const throw (variant_tree_error);
354+
) const;
355355

356356
/// Get default value for a named option.
357357
/// @return default value for a given option's path.
358358
template <class T>
359359
T def_value(
360360
const tree_path& a_path,
361361
const tree_path& a_root_path = tree_path()
362-
) const throw (variant_tree_error)
362+
) const
363363
{
364364
return def(a_path, a_root_path).data().get<T>();
365365
}
@@ -388,15 +388,14 @@ namespace config {
388388

389389
void validate(variant_tree& a_config, bool a_fill_defaults,
390390
const custom_validator& a_custom_validator = NULL
391-
) const throw(variant_tree_error);
391+
) const;
392392

393393
void validate(const variant_tree& a_config,
394394
const custom_validator& a_custom_validator = NULL
395-
) const throw(variant_tree_error);
395+
) const;
396396

397397
// Validate configuration tree stored in config()
398-
void validate(const custom_validator& a_custom_validator = NULL)
399-
const throw(variant_tree_error);
398+
void validate(const custom_validator& a_custom_validator = NULL) const;
400399

401400
protected:
402401
mutable tree_path m_root; // Path from configuration root
@@ -412,7 +411,7 @@ namespace config {
412411
void validate(variant_tree& a_config,
413412
const option_map& a_opts, bool fill_defaults,
414413
const custom_validator& a_custom_validator
415-
) const throw(variant_tree_error);
414+
) const;
416415

417416
static void add_option(option_map& a, const option& a_opt) {
418417
a.insert(std::make_pair(a_opt.name, a_opt));
@@ -459,20 +458,19 @@ namespace config {
459458
config_level_list& a_stack,
460459
bool a_fill_defaults,
461460
const custom_validator& a_custom_validator
462-
) const throw(variant_tree_error);
461+
) const;
463462

464463
void check_option(
465464
config_level_list& a_stack,
466465
typename variant_tree_base::value_type& a_vt,
467466
bool a_fill_defaults,
468467
const custom_validator& a_custom_validator
469-
) const throw(std::invalid_argument, variant_tree_error);
468+
) const;
470469

471470
void check_unique(const tree_path& a_root, const variant_tree_base& a_config,
472-
const option_map& a_opts) const throw(variant_tree_error);
471+
const option_map& a_opts) const;
473472

474-
void check_required(config_level_list& a_stack) const
475-
throw (missing_required_option_error, variant_tree_error);
473+
void check_required(config_level_list& a_stack) const;
476474

477475
static option_type_t to_option_type(variant::value_type a_type);
478476

@@ -495,8 +493,7 @@ namespace config {
495493
}
496494

497495
tree_path strip_root(const tree_path& a_root_path,
498-
const tree_path& a_root = tree_path()) const
499-
throw(variant_tree_error);
496+
const tree_path& a_root = tree_path()) const;
500497

501498
static const option* find(tree_path& a_suffix, const option_map& a_options)
502499
throw ();

include/utxx/logger/logger.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ struct logger : boost::noncopyable {
446446
};
447447

448448
typedef delegate
449-
<void (const msg& a_msg, const char* a_buf, size_t a_size)
450-
throw(io_error)>
449+
<void (const msg& a_msg, const char* a_buf, size_t a_size)>
451450
on_msg_delegate_t;
452451

453452
// Maps macros to values that can be used in configuration
@@ -647,17 +646,17 @@ struct logger : boost::noncopyable {
647646
/// This method is used for configuration parsing.
648647
/// @param a_levels delimited log levels (e.g. "DEBUG | INFO | WARNING").
649648
[[deprecated]]
650-
static int parse_log_levels(const std::string& levels) throw(std::runtime_error)
649+
static int parse_log_levels(const std::string& levels)
651650
{ return utxx::parse_log_levels(levels); }
652651

653652
/// Converts a string (e.g. "INFO") to the corresponding log level.
654653
[[deprecated]]
655-
static log_level parse_log_level(const std::string& a_level) throw(std::runtime_error)
654+
static log_level parse_log_level(const std::string& a_level)
656655
{ return utxx::parse_log_level(a_level); }
657656

658657
/// Convert a string (e.g. "INFO") to the log levels greater or equal to it.
659658
[[deprecated]]
660-
static int parse_min_log_level(const std::string& a_level) throw(std::runtime_error)
659+
static int parse_min_log_level(const std::string& a_level)
661660
{ return utxx::parse_min_log_level(a_level); }
662661

663662
/// String representation of log levels enabled by default. Used in config
@@ -829,8 +828,7 @@ struct logger_impl {
829828
/// Name of the logger
830829
virtual const std::string& name() const = 0;
831830

832-
virtual bool init(const variant_tree& a_config)
833-
throw(badarg_error, io_error) = 0;
831+
virtual bool init(const variant_tree& a_config) = 0;
834832

835833
/// Dump all settings to stream
836834
virtual std::ostream& dump(std::ostream& out, const std::string& a_prefix) const = 0;

include/utxx/logger/logger_impl_console.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ class logger_impl_console: public logger_impl {
7272
/// Dump all settings to stream
7373
std::ostream& dump(std::ostream& out, const std::string& a_prefix) const;
7474

75-
bool init(const variant_tree& a_config)
76-
throw(badarg_error, io_error);
75+
bool init(const variant_tree& a_config);
7776

78-
void log_msg(const logger::msg& a_msg, const char* a_buf, size_t a_size)
79-
throw (io_error);
77+
void log_msg(const logger::msg& a_msg, const char* a_buf, size_t a_size);
8078
};
8179

8280
} // namespace utxx

include/utxx/logger/logger_impl_file.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ class logger_impl_file: public logger_impl {
9797
/// Dump all settings to stream
9898
std::ostream& dump(std::ostream& out, const std::string& a_prefix) const;
9999

100-
bool init(const variant_tree& a_config)
101-
throw(badarg_error, io_error);
100+
bool init(const variant_tree& a_config);
102101

103-
void log_msg(const logger::msg& a_msg, const char* a_buf, size_t a_size)
104-
throw(io_error);
102+
void log_msg(const logger::msg& a_msg, const char* a_buf, size_t a_size);
105103
};
106104

107105
} // namespace utxx

include/utxx/logger/logger_impl_syslog.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@ class logger_impl_syslog: public logger_impl {
8888
/// Dump all settings to stream
8989
std::ostream& dump(std::ostream& out, const std::string& a_prefix) const;
9090

91-
bool init(const variant_tree& a_config)
92-
throw(badarg_error, io_error);
91+
bool init(const variant_tree& a_config);
9392

94-
void log_msg(const logger::msg& a_msg, const char* a_buf, size_t a_size)
95-
throw(io_error);
93+
void log_msg(const logger::msg& a_msg, const char* a_buf, size_t a_size);
9694
};
9795

9896
} // namespace utxx

include/utxx/logger/logger_util.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ namespace utxx {
6464
/// Converts a delimited string to a bitmask of corresponding levels.
6565
/// This method is used for configuration parsing.
6666
/// @param a_levels delimited log levels (e.g. "DEBUG | INFO | WARNING").
67-
int parse_log_levels(const std::string& levels) throw(std::runtime_error);
67+
int parse_log_levels(const std::string& levels);
6868

6969
/// Converts a string (e.g. "INFO") to the corresponding log level.
70-
log_level parse_log_level(const std::string& a_level) throw(std::runtime_error);
70+
log_level parse_log_level(const std::string& a_level);
7171

7272
/// Convert a string (e.g. "INFO") to the log levels greater or equal to it.
73-
int parse_min_log_level(const std::string& a_level) throw(std::runtime_error);
73+
int parse_min_log_level(const std::string& a_level);
7474

7575
} // namespace utxx

include/utxx/pcap.hpp

+43-4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ struct pcap {
9898
return std::string(buf);
9999
}
100100

101+
template <int N>
102+
char* src(char (&buf)[N]) const {
103+
char* p = fmt(buf, src_ip());
104+
assert(p-buf <= N);
105+
return p;
106+
}
107+
template <int N>
108+
char* dst(char (&buf)[N]) const {
109+
char* p = fmt(buf, dst_ip());
110+
assert(p-buf <= N);
111+
return p;
112+
}
113+
101114
template <int N>
102115
static char* fmt(char (&p)[N], uint32_t ip) {
103116
static_assert(N >= 16, "Buffer too small!");
@@ -115,14 +128,27 @@ struct pcap {
115128
uint16_t dst_port() const { return ntohs(udp.dest); }
116129

117130
std::string src() const {
118-
char buf[32]; fmt(ip_frame::fmt(buf, src_ip()), src_port());
131+
char buf[32]; src(buf);
119132
return std::string(buf);
120133
}
121134
std::string dst() const {
122-
char buf[32]; fmt(ip_frame::fmt(buf, dst_ip()), dst_port());
135+
char buf[32]; dst(buf);
123136
return std::string(buf);
124137
}
125138

139+
template <int N>
140+
char* src(char (&buf)[N]) const {
141+
char* p = fmt(ip_frame::fmt(buf, src_ip()), src_port());
142+
assert(p-buf <= N);
143+
return p;
144+
}
145+
template <int N>
146+
char* dst(char (&buf)[N]) const {
147+
char* p = fmt(ip_frame::fmt(buf, dst_ip()), dst_port());
148+
assert(p-buf <= N);
149+
return p;
150+
}
151+
126152
private:
127153
static char* fmt(char* buf, uint16_t port) {
128154
return buf + sprintf(buf, ":%d", port);
@@ -138,14 +164,27 @@ struct pcap {
138164
uint16_t dst_port() const { return ntohs(tcp.dest); }
139165

140166
std::string src() const {
141-
char buf[32]; fmt(ip_frame::fmt(buf, src_ip()), src_port());
167+
char buf[32]; src(buf);
142168
return std::string(buf);
143169
}
144170
std::string dst() const {
145-
char buf[32]; fmt(ip_frame::fmt(buf, dst_ip()), dst_port());
171+
char buf[32]; dst(buf);
146172
return std::string(buf);
147173
}
148174

175+
template <int N>
176+
char* src(char (&buf)[N]) const {
177+
char* p = fmt(ip_frame::fmt(buf, src_ip()), src_port());
178+
assert(p-&buf[0] <= N);
179+
return p;
180+
}
181+
template <int N>
182+
char* dst(char (&buf)[N]) const {
183+
char* p = fmt(ip_frame::fmt(buf, dst_ip()), dst_port());
184+
assert(p-&buf[0] <= N);
185+
return p;
186+
}
187+
149188
private:
150189
static char* fmt(char* buf, uint16_t port) {
151190
return buf + sprintf(buf, ":%d", port);

include/utxx/persist_array.hpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ namespace utxx {
110110
T* m_begin;
111111
T* m_end;
112112

113-
void check_range(size_t a_id) const throw (badarg_error) {
113+
void check_range(size_t a_id) const {
114114
size_t n = m_header->max_recs;
115115
if (likely(a_id < n))
116116
return;
@@ -158,7 +158,7 @@ namespace utxx {
158158
/// @return true if the storage file didn't exist and was created
159159
bool init(const char* a_filename, size_t a_max_recs, bool a_read_only = false,
160160
int a_mode = default_file_mode(), void const* a_map_address = nullptr,
161-
int a_map_options = 0) throw (io_error, utxx::runtime_error);
161+
int a_map_options = 0);
162162

163163
/// Initialize the storage in shared memory.
164164
/// @param a_segment the shared memory segment
@@ -168,8 +168,7 @@ namespace utxx {
168168
/// @param a_max_recs max capacity of the storage in the number of records
169169
/// @return true if the shared memory object didn't exist and was created
170170
bool init(bip::fixed_managed_shared_memory& a_segment,
171-
const char* a_name, persist_attach_type a_flag, size_t a_max_recs)
172-
throw (utxx::runtime_error);
171+
const char* a_name, persist_attach_type a_flag, size_t a_max_recs);
173172

174173
size_t count() const { return m_header->rec_count.load(std::memory_order_relaxed); }
175174
size_t capacity() const { return m_header->max_recs; }
@@ -180,7 +179,7 @@ namespace utxx {
180179

181180
/// Allocate next record and return its ID.
182181
/// @return
183-
size_t allocate_rec() throw(utxx::runtime_error) {
182+
size_t allocate_rec() {
184183
auto error = [this]() {
185184
throw utxx::runtime_error
186185
("persist_array: Out of storage capacity (", this->m_storage_name, ")!");
@@ -235,10 +234,10 @@ namespace utxx {
235234
/// @return id of the given object in the storage
236235
size_t id_of(const T* a_rec) const { return a_rec - m_begin; }
237236

238-
const T& operator[] (size_t a_id) const throw(badarg_error) {
237+
const T& operator[] (size_t a_id) const {
239238
check_range(a_id); return *get(a_id);
240239
}
241-
T& operator[] (size_t a_id) throw(badarg_error) {
240+
T& operator[] (size_t a_id) {
242241
check_range(a_id); return *get(a_id);
243242
}
244243

@@ -314,8 +313,8 @@ namespace utxx {
314313

315314
template <typename T, size_t NLocks, typename Lock, typename Ext>
316315
bool persist_array<T,NLocks,Lock,Ext>::
317-
init(const char* a_filename, size_t a_max_recs, bool a_read_only, int a_mode, void const* a_map_address, int a_map_options)
318-
throw (io_error, utxx::runtime_error)
316+
init(const char* a_filename, size_t a_max_recs, bool a_read_only, int a_mode,
317+
void const* a_map_address, int a_map_options)
319318
{
320319
auto sz = total_size(a_max_recs);
321320

@@ -439,7 +438,6 @@ namespace utxx {
439438
bool persist_array<T,NLocks,Lock,Ext>::
440439
init(bip::fixed_managed_shared_memory& a_segment,
441440
const char* a_name, persist_attach_type a_flag, size_t a_max_recs)
442-
throw(utxx::runtime_error)
443441
{
444442
std::pair<char*, size_t> fres = a_segment.find<char>(a_name);
445443

include/utxx/timestamp.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ class timestamp {
269269
//---------------------------------------------------------------------------
270270
/// Streaming support for time_val
271271
//---------------------------------------------------------------------------
272-
inline std::ostream& operator<< (std::ostream& out, time_val a) {
272+
template <typename Stream>
273+
inline Stream& operator<< (Stream& out, time_val a) {
273274
return out << timestamp::to_string(a, DATE_TIME_WITH_USEC, false);
274275
}
275276

0 commit comments

Comments
 (0)