Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ReadMailReallyFast/code
1 result
Show changes
Commits on Source (2)
......@@ -17,10 +17,6 @@ namespace rmrf::net {
io.stop();
this->net_socket.reset();
}
if (destructor_cb) {
destructor_cb(exit_status_t::NO_ERROR);
}
}
void connection_client::cb_ev(::ev::io& w, int events) {
......
......@@ -38,11 +38,6 @@ public:
*/
typedef std::function<void(const iorecord&)> incomming_data_cb;
/**
* A callback for the destructor must match this definition.
*/
typedef std::function<void(exit_status_t)> dtor_cb_type;
static const unsigned int no_rate_limit = 0;
protected:
......@@ -52,7 +47,6 @@ private:
::ev::io io;
::ev::async async;
ioqueue<iorecord> write_queue;
const dtor_cb_type destructor_cb;
protected:
bool server_active = false;
private:
......@@ -76,10 +70,14 @@ public:
* @param socket_fd The file descriptor to register with libev
* @param peer_address_ The remote address the client is connected to
*/
connection_client(auto_fd&& socket_fd, const socketaddr& peer_address_, const dtor_cb_type destructor_cb_, const std::shared_ptr<::ev::loop_ref> &loop_ref = nullptr) :
connection_client(
auto_fd&& socket_fd,
const socketaddr& peer_address_,
const std::shared_ptr<::ev::loop_ref> &loop_ref = nullptr
) :
net_socket(std::forward<auto_fd>(socket_fd)),
loop{loop_ref ? loop_ref : std::make_shared<::ev::loop_ref>(::ev::default_loop{})},
io{}, async{}, write_queue{}, destructor_cb{destructor_cb_},
io{}, async{}, write_queue{},
in_data_cb{}, own_address{}, peer_address{peer_address_}
{
async.set(*loop);
......
......@@ -26,10 +26,9 @@ tcp_client::tcp_client(
auto_fd&& socket_fd_,
const socketaddr& own_address_,
const socketaddr& peer_address_,
const dtor_cb_type dtor_cb_,
const std::shared_ptr<::ev::loop_ref>& loop_
) :
connection_client{std::forward<auto_fd>(socket_fd_), peer_address_, dtor_cb_, loop_}
connection_client{std::forward<auto_fd>(socket_fd_), peer_address_, loop_}
{
// TODO query own socket name (in the future this will be the only construcor, as we are generated by the client_factory, io is initialized in connection_client and we query the appropiate own endpoint here)
// TODO log created client
......
......@@ -36,7 +36,7 @@ public:
* @param socket_fd A file descriptor for an already open socket to be wrapped by this client
* @param peer_address The address the socket is bound to on the other end of the connection
*/
tcp_client(auto_fd&& socket_fd, const socketaddr& own_address, const socketaddr& peer_address, const dtor_cb_type dtor_cb_ = nullptr, const std::shared_ptr<::ev::loop_ref>& loop_ = nullptr);
tcp_client(auto_fd&& socket_fd, const socketaddr& own_address, const socketaddr& peer_address, const std::shared_ptr<::ev::loop_ref>& loop_ = nullptr);
/**
* This descructor will handle the resource deallocation and frees the socket. It also stops the
......
......@@ -131,7 +131,6 @@ std::shared_ptr<connection_client> tcp_server::await_raw_socket_incomming(const
std::move(client_socket),
get_own_address_after_connect(client_socket),
client_address,
nullptr,
loop
);
......
......@@ -39,10 +39,9 @@ public:
udp_client(
auto_fd&& socket_fd,
const socketaddr& own_address_,
const dtor_cb_type& dtor_cb_ = nullptr,
const std::shared_ptr<::ev::loop_ref>& loop_ = nullptr
) :
connection_client{std::forward<auto_fd>(socket_fd), socketaddr{}, dtor_cb_, loop_}
connection_client{std::forward<auto_fd>(socket_fd), socketaddr{}, loop_}
{
this->own_address = own_address_;
}
......
......@@ -95,7 +95,6 @@ std::shared_ptr<connection_client> unix_server::await_raw_socket_incomming(const
std::move(client_socket),
own_address,
peer_address,
nullptr,
loop
);
......
......@@ -22,7 +22,9 @@
using namespace rmrf::net;
const std::string udp_test_string = "TEST UDP PACKET";
const std::string test_string_tcp = "Moin from TCP";
const std::string test_string_udp = "Moin from UDP";
const std::string test_string_unix = "Moin from UNIX";
volatile bool tcp_called = false;
volatile bool udp_called = false;
......@@ -60,7 +62,7 @@ void ev_thread_callable() {
}
void udp_test_cb(const iorecord& data) {
BOOST_CHECK_EQUAL((char*) data.ptr(), udp_test_string.c_str());
BOOST_CHECK_EQUAL(data.str(), test_string_udp);
std::stringstream msg_ss;
msg_ss << "Received UDP packet from: " << data.get_address().str();
BOOST_TEST_MESSAGE(msg_ss.str());
......@@ -74,12 +76,13 @@ void run_udp_test() {
const socketaddr source_address = get_first_general_socketaddr("127.0.0.1", 9862, socket_t::UDP);
const socketaddr destination_address = get_first_general_socketaddr("127.0.0.1", 9863, socket_t::UDP);
auto sender = client_factory_construct_udp_client(source_address, udp_test_cb);
auto receiver = connect(destination_address, socket_t::UDP);
udp_source_family = destination_address.family();
auto sender = client_factory_construct_udp_client(source_address, nullptr);
auto receiver = client_factory_construct_udp_client(destination_address, udp_test_cb);
udp_packet<1024> data;
data << udp_test_string;
data << test_string_udp;
sender->send_packet(destination_address, data);
std::this_thread::yield();
......@@ -105,11 +108,11 @@ void run_tcp_test(const socketaddr& interface_addr) {
auto client = connect("127.0.0.1", "9861");
client->set_incomming_data_callback(
[](const iorecord& data) {
BOOST_CHECK_EQUAL(data.str(), "Moin");
BOOST_CHECK_EQUAL(data.str(), test_string_tcp);
tcp_called = true;
});
const std::string moin_string("Moin");
client->write_data(iorecord(moin_string.c_str(), moin_string.length()));
client->write_data(iorecord(test_string_tcp.c_str(), test_string_tcp.length()));
std::this_thread::yield();
std::this_thread::sleep_for(100ms);
......@@ -136,12 +139,11 @@ void run_unix_test() {
auto client = connect(socket_name);
client->set_incomming_data_callback(
[](const iorecord& data) {
BOOST_CHECK_EQUAL(data.str(), "Moin, von UNIX");
BOOST_CHECK_EQUAL(data.str(), test_string_unix);
unix_called = true;
});
const std::string moin_string("Moin, von UNIX");
client->write_data(iorecord(moin_string.c_str(), moin_string.length()));
client->write_data(iorecord(test_string_unix.c_str(), test_string_unix.length()));
std::this_thread::yield();
std::this_thread::sleep_for(100ms);
......@@ -155,7 +157,7 @@ BOOST_AUTO_TEST_CASE(Netio_Socket_TCP) {
std::thread ev_thread(ev_thread_callable);
const auto interface_addr = get_first_general_socketaddr("127.0.0.1", 9861);
(void)interface_addr;
//(void)interface_addr;
BOOST_CHECK_NO_THROW(run_tcp_test(interface_addr));
......