Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ add_library ( chops::chops_net_ip ALIAS chops_net_ip )
# dependencies needed for main library

include ( cmake/download_cpm.cmake )
CPMAddPackage ( "gh:connectivecpp/shared-buffer@1.0.4" )
CPMAddPackage ( "gh:martinmoene/expected-lite@0.8.0" )
CPMAddPackage ( "gh:connectivecpp/shared-buffer@1.0.5" )
CPMAddPackage ( "gh:martinmoene/expected-lite@0.10.0" )

include ( cmake/download_asio_cpm.cmake )

Expand Down
2 changes: 1 addition & 1 deletion cmake/download_asio_cpm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set ( CMAKE_THREAD_PREFER_PTHREAD TRUE )
set ( THREADS_PREFER_PTHREAD_FLAG TRUE )
find_package ( Threads REQUIRED )

CPMAddPackage ( "gh:chriskohlhoff/asio#asio-1-34-0@1.34.0" )
CPMAddPackage ( "gh:chriskohlhoff/asio#asio-1-36-0@1.36.0" )

# ASIO doesn't use CMake, we have to configure it manually. Extra notes for using on Windows:
#
Expand Down
2 changes: 1 addition & 1 deletion cmake/download_cpm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.0/CPM.cmake
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.42.0/CPM.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
6 changes: 3 additions & 3 deletions example/chat_server_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ int main(int argc, char *argv[])
// add to or remove @c io_interface from list in sta
sta(iof, n, flag);
if (flag) {
iof.start_io(DELIM, msg_hndlr);
auto e{iof.start_io(DELIM, msg_hndlr)};
}
};

Expand All @@ -159,7 +159,7 @@ int main(int argc, char *argv[])
auto net_entity = server.make_tcp_acceptor(port.c_str());
assert(net_entity.is_valid());
// start network entity, emplace handlers
net_entity.start(io_state_chng_hndlr, err_func);
auto se{net_entity.start(io_state_chng_hndlr, err_func)};

std::cout << "chops-net-ip chat server demo" << std::endl;
std::cout << " port: " << port << std::endl;
Expand All @@ -181,7 +181,7 @@ int main(int argc, char *argv[])
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
// shutdown
std::cerr << "shutdown...\n";
net_entity.stop();
auto e{net_entity.stop()};

std::this_thread::sleep_for(std::chrono::milliseconds(200));

Expand Down
10 changes: 5 additions & 5 deletions example/echo_binary_text_client_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int main(int argc, char* argv[]) {
(io_interface iof, std::size_t n, bool flag) {

if (flag) {
iof.start_io(HDR_SIZE, msg_hndlr, msg_frame);
auto e{iof.start_io(HDR_SIZE, msg_hndlr, msg_frame)};
}

};
Expand All @@ -168,7 +168,7 @@ int main(int argc, char* argv[]) {
net_entity_connect = echo_client.make_tcp_connector(port.c_str(), ip_address.c_str());
assert(net_entity_connect.is_valid());
// start @c network_entity, emplace handlers
net_entity_connect.start(io_state_chng_hndlr, err_func);
auto se{net_entity_connect.start(io_state_chng_hndlr, err_func)};

// begin
std::cout << "chops-net-ip binary text echo demo - client" << std::endl;
Expand Down Expand Up @@ -210,14 +210,14 @@ int main(int argc, char* argv[]) {
buf_out.append(s.data(), s.size()); // now add the text data
// send message to server (TCP_acceptor)
// tcp_iof.send(buf_out.data(), buf_out.size());
net_entity_connect.visit_io_output([&buf_out] (io_output io_out) {
auto err{net_entity_connect.visit_io_output([&buf_out] (io_output io_out) {
io_out.send(buf_out.data(), buf_out.size());
} // end lambda
);
)};
} // end while

// cleanup
net_entity_connect.stop();
auto e{net_entity_connect.stop()};
wk.reset();

return EXIT_SUCCESS;
Expand Down
6 changes: 3 additions & 3 deletions example/echo_binary_text_server_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ int main(int argc, char* argv[]) {
(io_interface iof, std::size_t n, bool flag) {

if (flag) {
iof.start_io(HDR_SIZE, msg_hndlr, msg_frame);
auto e{iof.start_io(HDR_SIZE, msg_hndlr, msg_frame)};
}

};
Expand All @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) {
net_entity_accept = echo_server.make_tcp_acceptor(port.c_str());
assert(net_entity_accept.is_valid());
// start network entity, emplace handlers
net_entity_accept.start(io_state_chng_hndlr, err_func);
auto se{net_entity_accept.start(io_state_chng_hndlr, err_func)};

// begin
std::cout << "chops-net-ip binary text echo demo - server" << std::endl;
Expand All @@ -184,7 +184,7 @@ int main(int argc, char* argv[]) {
std::getline(std::cin, s); // pause until return

// cleanup
net_entity_accept.stop();
auto e{net_entity_accept.stop()};
wk.reset();

return EXIT_SUCCESS;
Expand Down
10 changes: 5 additions & 5 deletions example/local_echo_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int main() {
auto io_state_chng_connect = [msg_hndlr_connect]
(tcp_io_interface iof, std::size_t n, bool flag) {
if (flag && n == 1) {
iof.start_io("\n", msg_hndlr_connect);
auto e{iof.start_io("\n", msg_hndlr_connect)};
}

};
Expand All @@ -90,7 +90,7 @@ int main() {
(tcp_io_interface iof, std::size_t n, bool flag)
{
if (flag && n == 1) {
iof.start_io("\n", msg_hndlr_accept);
auto e{iof.start_io("\n", msg_hndlr_accept)};
}
};

Expand Down Expand Up @@ -140,14 +140,14 @@ int main() {
s += "\n"; // needed for deliminator
// send string from @c tcp_connector to @c tcp_acceptor
auto visit_out = [&s] (io_output io_out) { io_out.send(s.data(), s.size());};
tcne.visit_io_output(visit_out);
auto e{tcne.visit_io_output(visit_out)};
// pause so returned string is displayed before next prompt
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}

// must shutdown the net entities
tcne.stop();
tane.stop();
auto e1{tcne.stop()};
auto e2{tane.stop()};
wk.reset();

return EXIT_SUCCESS;
Expand Down
10 changes: 5 additions & 5 deletions example/simple_chat_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,20 @@ int main(int argc, char* argv[]) {
screen.insert_scroll_line("io_interface start" + DELIM, SYSTEM);
screen.draw_screen();
}
iof.start_io(DELIM, msg_hndlr);
auto e{iof.start_io(DELIM, msg_hndlr)};
// tcp_iof = iof; // return @c iof to main
} else {
// since we are peer to peer, reject >1 connections
screen.insert_scroll_line("2nd tcp_connector client rejected" +
DELIM, SYSTEM);
screen.draw_screen();
iof.start_io(DELIM, msg_hndlr);
auto e1{iof.start_io(DELIM, msg_hndlr)};
const std::string err = "only one tcp connection allowed";
auto ret = iof.make_io_output();
auto io_out = *ret;
io_out.send(err.data(), err.size());
std::this_thread::sleep_for(std::chrono::milliseconds(500));
iof.stop_io();
auto e2{iof.stop_io()};
}
} else { // flag false
if (print_errors) {
Expand Down Expand Up @@ -230,7 +230,7 @@ int main(int argc, char* argv[]) {
}
assert(net_entity.is_valid());
// start network entity, emplace handlers
net_entity.start(io_state_chng_hndlr, err_func);
auto se{net_entity.start(io_state_chng_hndlr, err_func)};

/**************************************/
/********** user interaction **********/
Expand Down Expand Up @@ -267,7 +267,7 @@ int main(int argc, char* argv[]) {
/********** shutdown **********/
/******************************/

net_entity.stop();
auto e{net_entity.stop()};
wk.reset();

return EXIT_SUCCESS;
Expand Down
6 changes: 3 additions & 3 deletions example/udp_receiver_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int main(int argc, char* argv[]) {
(udp_io_interface iof, std::size_t n, bool flag) {

if (flag) {
iof.start_io(MAX_BUF, msg_hndlr);
auto e{iof.start_io(MAX_BUF, msg_hndlr)};
if (print_errors) {
std::cout << "io state change: start_io" << std::endl;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ int main(int argc, char* argv[]) {
udp_ne = udp_receive.make_udp_unicast(port.c_str());
assert(udp_ne.is_valid());

udp_ne.start(io_state_chng_hndlr, err_func);
auto se {udp_ne.start(io_state_chng_hndlr, err_func)};

// pause for user input, then quit
std::string s;
Expand All @@ -177,7 +177,7 @@ int main(int argc, char* argv[]) {
/********** shutdown **********/
/******************************/

udp_ne.stop();
auto stoperr {udp_ne.stop()};
// wk.stop();
wk.reset();

Expand Down
16 changes: 8 additions & 8 deletions include/net_ip_component/io_state_change.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Cliff Green
*
* Copyright (c) 2018-2019 by Cliff Green
* Copyright (c) 2018-2026 by Cliff Green
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -67,7 +67,7 @@ auto make_simple_variable_len_msg_frame_io_state_change (std::size_t hdr_size,
return [hdr_size, hdr_func, mh = std::move(msg_hdlr)]
(tcp_io_interface io, std::size_t num, bool starting) {
if (starting) {
io.start_io(hdr_size, std::move(mh), hdr_func);
auto r{io.start_io(hdr_size, std::move(mh), hdr_func)};
}
};
}
Expand Down Expand Up @@ -96,7 +96,7 @@ auto make_msg_frame_io_state_change (std::size_t hdr_size,
return [hdr_size, mh = std::move(msg_hdlr), mf = std::move(msg_frame)]
(tcp_io_interface io, std::size_t num, bool starting) {
if (starting) {
io.start_io(hdr_size, std::move(mh), std::move(mf));
auto r{io.start_io(hdr_size, std::move(mh), std::move(mf))};
}
};
}
Expand All @@ -121,7 +121,7 @@ auto make_delimiter_read_io_state_change (std::string_view delim, MH&& msg_hdlr)
return [delim, mh = std::move(msg_hdlr)]
(tcp_io_interface io, std::size_t num, bool starting) {
if (starting) {
io.start_io(delim, std::move(mh));
auto r{io.start_io(delim, std::move(mh))};
}
};
}
Expand All @@ -147,7 +147,7 @@ auto make_read_io_state_change (std::size_t rd_size, MH&& msg_hdlr) {
return [rd_size, mh = std::move(msg_hdlr)]
(basic_io_interface<IOT> io, std::size_t num, bool starting) {
if (starting) {
io.start_io(rd_size, std::move(mh));
auto r{io.start_io(rd_size, std::move(mh))};
}
};
}
Expand All @@ -163,7 +163,7 @@ template <typename IOT>
auto make_send_only_io_state_change () {
return [] (basic_io_interface<IOT> io, std::size_t num, bool starting) {
if (starting) {
io.start_io();
auto r{io.start_io()};
}
};
}
Expand Down Expand Up @@ -191,7 +191,7 @@ auto make_default_endp_io_state_change (const asio::ip::udp::endpoint& endp,
return [max_size, endp, mh = std::move(msg_hdlr)]
(udp_io_interface io, std::size_t num, bool starting) {
if (starting) {
io.start_io(endp, max_size, std::move(mh));
auto r{io.start_io(endp, max_size, std::move(mh))};
}
};
}
Expand All @@ -210,7 +210,7 @@ inline
auto make_send_only_default_endp_io_state_change (const asio::ip::udp::endpoint& endp) {
return [endp] (udp_io_interface io, std::size_t num, bool starting) {
if (starting) {
io.start_io(endp);
auto r {io.start_io(endp)};
}
};
}
Expand Down
16 changes: 8 additions & 8 deletions include/net_ip_component/output_queue_stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @author Cliff Green
*
* Copyright (c) 2019 by Cliff Green
* Copyright (c) 2019-2026 by Cliff Green
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -48,7 +48,7 @@ template <typename Iter>
output_queue_stats accumulate_output_queue_stats(Iter beg, Iter end) {
return std::accumulate(beg, end, output_queue_stats(),
[] (const output_queue_stats& sum, const auto& io) {
auto rhs = io.get_output_queue_stats();
auto rhs {io.get_output_queue_stats()};
return rhs ? output_queue_stats { sum.output_queue_size + rhs->output_queue_size,
sum.bytes_in_output_queue + rhs->bytes_in_output_queue } :
sum;
Expand Down Expand Up @@ -123,14 +123,14 @@ output_queue_stats accumulate_net_entity_output_queue_stats(Iter beg, Iter end)
return std::accumulate(beg, end, output_queue_stats(),
[] (const output_queue_stats& sum, const auto& ne) {
output_queue_stats st{};
ne.visit_io_output([&st] (basic_io_output<IOT> io) {
auto r = io.get_output_queue_stats();
if (r) {
st.output_queue_size += r->output_queue_size;
st.bytes_in_output_queue += r->bytes_in_output_queue;
auto r1 {ne.visit_io_output([&st] (basic_io_output<IOT> io) {
auto r2 {io.get_output_queue_stats()};
if (r2) {
st.output_queue_size += r2->output_queue_size;
st.bytes_in_output_queue += r2->bytes_in_output_queue;
}
}
);
)};
return output_queue_stats {sum.output_queue_size + st.output_queue_size,
sum.bytes_in_output_queue + st.bytes_in_output_queue};
}
Expand Down
8 changes: 4 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ cmake_minimum_required ( VERSION 3.14 FATAL_ERROR )
project ( chops_net_ip_test LANGUAGES CXX )

# dependencies, Catch2 and Connective C++
CPMAddPackage ( "gh:connectivecpp/utility-rack@1.0.4" )
CPMAddPackage ( "gh:connectivecpp/wait-queue@1.2.3" )
CPMAddPackage ( "gh:connectivecpp/binary-serialize@1.0.4" )
CPMAddPackage ( "gh:connectivecpp/utility-rack@1.0.6" )
CPMAddPackage ( "gh:connectivecpp/wait-queue@1.2.4" )
CPMAddPackage ( "gh:connectivecpp/binary-serialize@1.0.5" )

CPMAddPackage ( "gh:catchorg/Catch2@3.8.0" )
CPMAddPackage ( "gh:catchorg/Catch2@3.11.0" )

add_subdirectory ( net_ip )
add_subdirectory ( net_ip_component )
Expand Down
2 changes: 1 addition & 1 deletion test/net_ip/detail/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set ( test_app_names io_common_test
net_entity_common_test
output_queue_test
tcp_acceptor_test
tcp_connector_test
# tcp_connector_test
tcp_io_test
udp_entity_io_test
wp_access_test )
Expand Down
4 changes: 2 additions & 2 deletions test/net_ip/detail/tcp_connector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ TEST_CASE ( "Tcp connector test, LF msgs, one-way, interval 0, 15 connectors",
TEST_CASE ( "Tcp connector test, LF msgs, two-way, interval 0, 15 connectors, many msgs",
"[tcp_conn] [lf_msg] [two_way] [interval_0] [connectors_15] [many]" ) {

perform_test ( make_msg_vec (make_lf_text_msg, "Super fast!", 'S', 25*num_msgs),
make_fixed_size_msg_vec(25*num_msgs),
perform_test ( make_msg_vec (make_lf_text_msg, "Super fast!", 'S', 15*num_msgs),
make_fixed_size_msg_vec(15*num_msgs),
true, 0, 15,
std::string_view("\n"), make_empty_lf_text_msg() );

Expand Down
8 changes: 4 additions & 4 deletions test/net_ip/net_entity_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ void test_tcp_msg_send (const vec_buf& in_msg_vec,
// wait for another io_output to signal end of processing
io_out = *(out_wq.wait_and_pop());

net_conn.stop();
net_acc.stop();
auto r1 {net_conn.stop()};
auto r2 {net_acc.stop()};

REQUIRE (in_msg_vec.size() == acc_cnt);
REQUIRE (in_msg_vec.size() == conn_cnt);
Expand Down Expand Up @@ -223,8 +223,8 @@ void test_udp_msg_send (const vec_buf& in_msg_vec,

std::this_thread::sleep_for(std::chrono::milliseconds(50));

net_udp_send.stop();
net_udp_recv.stop();
auto r1 {net_udp_send.stop()};
auto r2 {net_udp_recv.stop()};


REQUIRE_FALSE (*(net_udp_send.is_started()));
Expand Down
Loading