Skip to content

Commit 7ee0351

Browse files
Additional updating, cleanup, and porting to C++20
1 parent 9f7c805 commit 7ee0351

File tree

10 files changed

+49
-49
lines changed

10 files changed

+49
-49
lines changed

include/net_ip/detail/tcp_acceptor.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* @author Cliff Green
1010
*
11-
* Copyright (c) 2018-2019 by Cliff Green
11+
* Copyright (c) 2018-2025 by Cliff Green
1212
*
1313
* Distributed under the Boost Software License, Version 1.0.
1414
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -39,8 +39,6 @@
3939

4040
#include "net_ip/basic_io_output.hpp"
4141

42-
#include "utility/erase_where.hpp"
43-
4442
namespace chops {
4543
namespace net {
4644
namespace detail {
@@ -231,7 +229,7 @@ class tcp_acceptor : public std::enable_shared_from_this<tcp_acceptor> {
231229
// this code invoked via a posted function object, allowing the TCP IO handler
232230
// to completely shut down
233231
void notify_me(std::error_code err, tcp_io_shared_ptr iop) {
234-
chops::erase_where(m_io_handlers, iop);
232+
std::erase_if (m_io_handlers, [iop] (auto sp) { return iop == sp; } );
235233
m_entity_common.call_error_cb(iop, err);
236234
m_entity_common.call_io_state_chg_cb(iop, m_io_handlers.size(), false);
237235
}

include/net_ip/detail/tcp_io.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* @author Cliff Green
1010
*
11-
* Copyright (c) 2017-2019 by Cliff Green
11+
* Copyright (c) 2017-2025 by Cliff Green
1212
*
1313
* Distributed under the Boost Software License, Version 1.0.
1414
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -42,7 +42,7 @@
4242
#include "net_ip/basic_io_output.hpp"
4343
#include "net_ip/simple_variable_len_msg_frame.hpp"
4444

45-
#include "marshall/shared_buffer.hpp"
45+
#include "buffer/shared_buffer.hpp"
4646

4747
namespace chops {
4848
namespace net {

include/net_ip/detail/udp_entity_io.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* @author Cliff Green
1010
*
11-
* Copyright (c) 2018-2019 by Cliff Green
11+
* Copyright (c) 2018-2025 by Cliff Green
1212
*
1313
* Distributed under the Boost Software License, Version 1.0.
1414
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -40,7 +40,7 @@
4040
#include "net_ip/basic_io_output.hpp"
4141
#include "net_ip/endpoints_resolver.hpp"
4242

43-
#include "marshall/shared_buffer.hpp"
43+
#include "buffer/shared_buffer.hpp"
4444

4545
//////
4646
// #include <iostream>

include/net_ip/net_entity.hpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @author Cliff Green
88
*
9-
* Copyright (c) 2017-2019 by Cliff Green
9+
* Copyright (c) 2017-2025 by Cliff Green
1010
*
1111
* Distributed under the Boost Software License, Version 1.0.
1212
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -37,16 +37,15 @@
3737

3838
#include "net_ip/io_type_decls.hpp"
3939

40-
#include "utility/overloaded.hpp"
41-
4240
namespace chops {
4341
namespace net {
4442

45-
// Cliff note: when C++ 20 lambda templates are available much of this code can be simplified,
46-
// since most of it is generic (just doesn't have the specific type parameter available as
47-
// needed in the right place). Stating it another way, there is waaaaaaay too much boilerplate
48-
// code (it may be possible to simplify with C++17 techniques that I don't know yet).
49-
43+
namespace detail {
44+
// std::visit utility taken directly from cppreference
45+
template<class... Ts>
46+
struct overloaded : Ts... { using Ts::operator()...; };
47+
}
48+
5049
/**
5150
* @brief The @c net_entity class provides the primary application interface
5251
* into the TCP acceptor, TCP connector, and UDP entity functionality.
@@ -137,7 +136,7 @@ class net_entity {
137136
*/
138137
auto is_started() const ->
139138
nonstd::expected<bool, std::error_code> {
140-
return std::visit(chops::overloaded {
139+
return std::visit(detail::overloaded {
141140
[] (const udp_wp& wp) -> nonstd::expected<bool, std::error_code> {
142141
return detail::wp_access<bool>(wp,
143142
[] (detail::udp_entity_io_shared_ptr sp) { return sp->is_started(); } );
@@ -175,7 +174,7 @@ class net_entity {
175174
template <typename F>
176175
auto visit_socket(F&& func) const ->
177176
nonstd::expected<void, std::error_code> {
178-
return std::visit(chops::overloaded {
177+
return std::visit(detail::overloaded {
179178
[&func] (const udp_wp& wp) -> nonstd::expected<void, std::error_code> {
180179
if constexpr (std::is_invocable_v<F, asio::ip::udp::socket&>) {
181180
return detail::wp_access_void(wp,
@@ -225,7 +224,7 @@ class net_entity {
225224
template <typename F>
226225
auto visit_io_output(F&& func) const ->
227226
nonstd::expected<std::size_t, std::error_code> {
228-
return std::visit(chops::overloaded {
227+
return std::visit(detail::overloaded {
229228
[&func] (const udp_wp& wp)-> nonstd::expected<std::size_t, std::error_code> {
230229
if constexpr (std::is_invocable_v<F, chops::net::udp_io_output>) {
231230
return detail::wp_access<std::size_t>(wp,
@@ -343,7 +342,7 @@ class net_entity {
343342
template <typename F1, typename F2>
344343
auto start(F1&& io_state_chg_func, F2&& err_func) ->
345344
nonstd::expected<void, std::error_code> {
346-
return std::visit(chops::overloaded {
345+
return std::visit(detail::overloaded {
347346
[&io_state_chg_func, &err_func] (const udp_wp& wp)->nonstd::expected<void, std::error_code> {
348347
if constexpr (std::is_invocable_v<F1, udp_io_interface, std::size_t, bool> &&
349348
std::is_invocable_v<F2, udp_io_interface, std::error_code>) {
@@ -389,7 +388,7 @@ class net_entity {
389388
*/
390389
auto stop() ->
391390
nonstd::expected<void, std::error_code> {
392-
return std::visit(chops::overloaded {
391+
return std::visit(detail::overloaded {
393392
[] (const udp_wp& wp)->nonstd::expected<void, std::error_code> {
394393
return detail::wp_access_void(wp,
395394
[] (detail::udp_entity_io_shared_ptr sp) { return sp->stop(); } );
@@ -414,7 +413,7 @@ class net_entity {
414413
*
415414
*/
416415
std::string_view stream_out() const noexcept {
417-
return std::visit(chops::overloaded {
416+
return std::visit(detail::overloaded {
418417
[] (const udp_wp& wp) { return "[UDP network entity]"; },
419418
[] (const acc_wp& wp) { return "[TCP acceptor network entity]"; },
420419
[] (const conn_wp& wp) { return "[TCP connector network entity]"; },
@@ -442,7 +441,7 @@ class net_entity {
442441
*/
443442

444443
inline bool operator==(const net_entity& lhs, const net_entity& rhs) noexcept {
445-
return std::visit(chops::overloaded {
444+
return std::visit(detail::overloaded {
446445
[] (const net_entity::udp_wp& lwp, const net_entity::udp_wp& rwp) {
447446
return lwp.lock() == rwp.lock();
448447
},
@@ -487,7 +486,7 @@ inline bool operator==(const net_entity& lhs, const net_entity& rhs) noexcept {
487486
* @return As described in the comments.
488487
*/
489488
inline bool operator<(const net_entity& lhs, const net_entity& rhs) noexcept {
490-
return std::visit(chops::overloaded {
489+
return std::visit(detail::overloaded {
491490
[] (const net_entity::udp_wp& lwp, const net_entity::udp_wp& rwp) {
492491
return lwp.lock() < rwp.lock();
493492
},

include/net_ip/net_ip.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141

4242
#include "net_ip/tcp_connector_timeout.hpp"
4343

44-
#include "utility/erase_where.hpp"
45-
#include "utility/overloaded.hpp"
46-
4744
namespace chops {
4845
namespace net {
4946

@@ -391,10 +388,17 @@ class net_ip {
391388
*/
392389
void remove(net_entity ent) {
393390
lg g(m_mutex);
394-
std::visit (chops::overloaded {
395-
[this] (detail::tcp_acceptor_weak_ptr p) { chops::erase_where(m_acceptors, p.lock()); },
396-
[this] (detail::tcp_connector_weak_ptr p) { chops::erase_where(m_connectors, p.lock()); },
397-
[this] (detail::udp_entity_io_weak_ptr p) { chops::erase_where(m_udp_entities, p.lock()); },
391+
// overloaded utility brought in from net_entity.hpp
392+
std::visit (detail::overloaded {
393+
[this] (detail::tcp_acceptor_weak_ptr p) {
394+
std::erase_if(m_acceptors, [p] (detail::tcp_acceptor_shared_ptr sp) { sp == p.lock(); } )
395+
},
396+
[this] (detail::tcp_connector_weak_ptr p) {
397+
std::erase_if(m_connectors, [p] (detail::tcp_connector_shared_ptr sp) { sp == p.lock(); } )
398+
},
399+
[this] (detail::udp_entity_io_weak_ptr p) {
400+
std::erase_if(m_udp_entities, [p] (detail::udp_entity_io_shared_ptr sp) { sp == p.lock(); } )
401+
}
398402
}, ent.m_wptr);
399403
}
400404

include/net_ip_component/send_to_all.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* The "send to all but one" functionality added by Thurman in Oct, 2019.
1212
*
13-
* Copyright (c) 2019 by Cliff Green, Thurman Gillespy
13+
* Copyright (c) 2019-2025 by Cliff Green, Thurman Gillespy
1414
*
1515
* Distributed under the Boost Software License, Version 1.0.
1616
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -31,8 +31,7 @@
3131

3232
#include "net_ip_component/output_queue_stats.hpp"
3333

34-
#include "utility/erase_where.hpp"
35-
#include "marshall/shared_buffer.hpp"
34+
#include "buffer/shared_buffer.hpp"
3635

3736
namespace chops {
3837
namespace net {
@@ -64,7 +63,7 @@ namespace net {
6463
template <typename IOT>
6564
class send_to_all {
6665
private:
67-
using lock_guard = std::lock_guard<std::mutex>;
66+
using lock_guard = std::scoped_lock<std::mutex>;
6867
using io_out = chops::net::basic_io_output<IOT>;
6968
using io_outs = std::vector<io_out>;
7069
using io_interface = chops::net::basic_io_interface<IOT>;
@@ -91,7 +90,7 @@ class send_to_all {
9190
*/
9291
void remove_io_output(io_out io) {
9392
lock_guard gd { m_mutex };
94-
chops::erase_where(m_io_outs, io);
93+
std::erase_if (m_io_outs, [io] (auto out) { return io == out; } );
9594
}
9695

9796
/**

test/test_data_blaster/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Multiple data sender / receiver (DSR) instances are running at the same time (at
88

99
A single instance of the monitor (either the C++ or Python version) shows statistics from the DSR instances. The monitor is also responsible for shutting down the DSRs. The same monitor instance can be running for both TCP and UDP DSRs (the log messages sent to the monitor from the DSRs specify whether the test data is being sent over TCP or UDP).
1010

11-
The message definitions between the DSRs and the monitor are text only, so binary endianness is not a factor, and will run on any platform. The data flowing between DSRs is marshalled and unmarshalled as needed by the DSRs.
11+
The message definitions between the DSRs and the monitor are text only, so binary endianness is not a factor, and will run on any platform. The data flowing between DSRs is serialized and deserialized as needed by the DSRs.
1212

1313
## Usage
1414

@@ -88,7 +88,7 @@ If the "reply" command line parameter is set, an incoming message is reflected b
8888

8989
Degenerate configurations are possible, with infinite message loops or where connection and shutdown timing is not clear. No special coding is in the T-DB to protect for bad configurations.
9090

91-
The DSR internal data messages uses the binary marshalled message format from the `shared_test` facilities (see `msg_handling.hpp` for specific code). The monitor messages are text based messages with all fields in a string format easy to unmarshall for Python applications.
91+
The DSR internal data messages uses the binary serialized message format from the `shared_test` facilities (see `msg_handling.hpp` for specific code). The monitor messages are text based messages with all fields in a string format easy to deserialize for Python applications.
9292

9393
The general logic flow:
9494
- Process command line arguments

test/test_data_blaster/monitor_connector.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
*
33
* @ingroup test_module
44
*
5-
* @brief Monitor message marshalling, unmarshalling, sending, and shutdown msg handling.
5+
* @brief Monitor message serializing, deserializing, sending, and shutdown msg handling.
66
*
77
* @author (fill in)
88
*
9-
* Copyright (c) 2019 by Cliff Green, (fill in)
9+
* Copyright (c) 2019-2025 by Cliff Green, (fill in)
1010
*
1111
* Distributed under the Boost Software License, Version 1.0.
1212
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -66,4 +66,4 @@ class monitor_connector {
6666
};
6767

6868
}
69-
}
69+
}

test/test_data_blaster/monitor_msg.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @author (fill in)
88
*
9-
* Copyright (c) 2019 by Cliff Green, (fill in)
9+
* Copyright (c) 2019-2025 by Cliff Green, (fill in)
1010
*
1111
* Distributed under the Boost Software License, Version 1.0.
1212
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -56,26 +56,26 @@ struct shutdown_msg {
5656
};
5757

5858

59-
inline chops::const_shared_buffer marshall_monitor_msg_data (const monitor_msg_data& msg_data) {
59+
inline chops::const_shared_buffer serialize_monitor_msg_data (const monitor_msg_data& msg_data) {
6060
// work in progress
6161
return null;
6262
}
6363

64-
inline monitor_msg_data unmarshall_monitor_msg_data (const chops::const_shared_buffer& buf) {
64+
inline monitor_msg_data deserialize_monitor_msg_data (const chops::const_shared_buffer& buf) {
6565
// work in progress
6666
return null;
6767
}
6868

69-
inline chops::const_shared_buffer marshall_shutdown_message() {
69+
inline chops::const_shared_buffer serialize_shutdown_message() {
7070
// work in progress
7171
return null;
7272
}
7373

74-
inline std::string unmarshall_shutdown_message() {
74+
inline std::string deserialize_shutdown_message() {
7575
// work in progress
7676
return null;
7777
}
7878

7979

8080
}
81-
}
81+
}

test/test_data_blaster/tcp_dsr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @author Cliff Green
99
*
10-
* Copyright (c) 2019 by Cliff Green
10+
* Copyright (c) 2019-2025 by Cliff Green
1111
*
1212
* Distributed under the Boost Software License, Version 1.0.
1313
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -35,7 +35,7 @@
3535
#include "net_ip_component/error_delivery.hpp"
3636

3737
#include "shared_test/msg_handling.hpp"
38-
#include "marshall/shared_buffer.hpp"
38+
#include "buffer/shared_buffer.hpp"
3939

4040
#include "test_data_blaster/dsr_args.hpp"
4141
#include "test_data_blaster/monitor_msg_handling.hpp"

0 commit comments

Comments
 (0)