Skip to content

Commit

Permalink
Fixed many clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianReimold committed Apr 19, 2024
1 parent 61b2641 commit f09df3c
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 28 deletions.
5 changes: 2 additions & 3 deletions ecaludp/include_with_udpcap/ecaludp/socket_npcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ namespace ecaludp
ECALUDP_EXPORT std::shared_ptr<ecaludp::OwningBuffer> receive_from(asio::ip::udp::endpoint& sender_endpoint, ecaludp::Error& error);

ECALUDP_EXPORT void async_receive_from(asio::ip::udp::endpoint& sender_endpoint
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, ecaludp::Error)>& completion_handler);

, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, const ecaludp::Error&)>& completion_handler);

private:
void receive_next_datagram_from(asio::ip::udp::endpoint& sender_endpoint
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, ecaludp::Error)>& completion_handler);
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, const ecaludp::Error&)>& completion_handler);

std::shared_ptr<ecaludp::OwningBuffer> handle_datagram(const std::shared_ptr<ecaludp::RawMemory>& buffer
, const std::shared_ptr<asio::ip::udp::endpoint>& sender_endpoint
Expand Down
2 changes: 1 addition & 1 deletion ecaludp/src/async_udpcap_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace ecaludp
, size_t max_buffer_size
, Udpcap::HostAddress& sender_address
, uint16_t& sender_port
, const std::function<void(ecaludp::Error&, size_t)>& read_handler)
, const std::function<void(const ecaludp::Error&, size_t)>& read_handler)
{
const std::unique_lock<std::mutex> lock(wait_thread_trigger_mutex_);
async_receive_from_parameters_queue_.push_back({ buffer, max_buffer_size, &sender_address, &sender_port, read_handler });
Expand Down
6 changes: 3 additions & 3 deletions ecaludp/src/async_udpcap_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ namespace ecaludp
, size_t max_buffer_size
, Udpcap::HostAddress& sender_address
, uint16_t& sender_port
, ecaludp::Error& error);
, ecaludp::Error& error);

void asyncReceiveFrom( char* buffer
, size_t max_buffer_size
, Udpcap::HostAddress& sender_address
, uint16_t& sender_port
, const std::function<void(ecaludp::Error&, size_t)>& read_handler);
, const std::function<void(const ecaludp::Error&, size_t)>& read_handler);

private:
static void toEcaludpError(const Udpcap::Error& udpcap_error, ecaludp::Error& ecaludp_error);
Expand All @@ -95,7 +95,7 @@ namespace ecaludp
size_t max_buffer_size_;
Udpcap::HostAddress* sender_address_;
uint16_t* sender_port_;
std::function<void(ecaludp::Error&, size_t)> read_handler_;
std::function<void(const ecaludp::Error&, size_t)> read_handler_;
};

Udpcap::UdpcapSocket udpcap_socket_;
Expand Down
6 changes: 3 additions & 3 deletions ecaludp/src/socket_npcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ namespace ecaludp


void SocketNpcap::async_receive_from(asio::ip::udp::endpoint& sender_endpoint
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, ecaludp::Error)>& completion_handler)
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, const ecaludp::Error&)>& completion_handler)
{
receive_next_datagram_from(sender_endpoint, completion_handler);
}

void SocketNpcap::receive_next_datagram_from(asio::ip::udp::endpoint& sender_endpoint
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, ecaludp::Error)>& completion_handler)
, const std::function<void(const std::shared_ptr<ecaludp::OwningBuffer>&, const ecaludp::Error&)>& completion_handler)

{
auto datagram_buffer = datagram_buffer_pool_->allocate();
Expand All @@ -164,7 +164,7 @@ namespace ecaludp
, buffer->size()
, *sender_address
, *sender_port
, [this, buffer, completion_handler, sender_address, sender_port, &sender_endpoint](ecaludp::Error& error, size_t bytes_received)
, [this, buffer, completion_handler, sender_address, sender_port, &sender_endpoint](const ecaludp::Error& error, size_t bytes_received)
{
if (error)
{
Expand Down
6 changes: 6 additions & 0 deletions samples/ecaludp_perftool/src/receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class Receiver
Receiver(const ReceiverParameters& parameters);
virtual ~Receiver();

// disable copy and move
Receiver(const Receiver&) = delete;
Receiver(Receiver&&) = delete;
Receiver& operator=(const Receiver&) = delete;
Receiver& operator=(Receiver&&) = delete;

virtual void start() = 0;

private:
Expand Down
5 changes: 3 additions & 2 deletions samples/ecaludp_perftool/src/receiver_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ ReceiverAsync::~ReceiverAsync()
if(work_)
work_.reset();

io_context_thread_->join();
if (io_context_thread_->joinable())
io_context_thread_->join();
}

void ReceiverAsync::start()
Expand Down Expand Up @@ -82,7 +83,7 @@ void ReceiverAsync::receive_message()
{
if (ec)
{
std::cout << "Error sending: " << ec.message() << '\n';
std::cerr << "Error sending: " << ec.message() << '\n';
socket_->close();
return;
}
Expand Down
6 changes: 6 additions & 0 deletions samples/ecaludp_perftool/src/receiver_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class ReceiverAsync : public Receiver
ReceiverAsync(const ReceiverParameters& parameters);
~ReceiverAsync() override;

// disable copy and move
ReceiverAsync(const ReceiverAsync&) = delete;
ReceiverAsync(ReceiverAsync&&) = delete;
ReceiverAsync& operator=(const ReceiverAsync&) = delete;
ReceiverAsync& operator=(ReceiverAsync&&) = delete;

void start() override;

private:
Expand Down
10 changes: 5 additions & 5 deletions samples/ecaludp_perftool/src/receiver_npcap_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
ReceiverNpcapAsync::ReceiverNpcapAsync(const ReceiverParameters& parameters)
: Receiver(parameters)
{
std::cout << "Receiver implementation: Asynchronous NPCAP" << std::endl;
std::cout << "Receiver implementation: Asynchronous NPCAP\n";
}

ReceiverNpcapAsync::~ReceiverNpcapAsync()
Expand All @@ -49,7 +49,7 @@ void ReceiverNpcapAsync::start()
}
catch (const std::exception& e)
{
std::cerr << "Error creating socket: " << e.what() << std::endl;
std::cerr << "Error creating socket: " << e.what()<< '\n';
exit(1);
}

Expand All @@ -61,17 +61,17 @@ void ReceiverNpcapAsync::receive_message()
auto endpoint = std::make_shared<asio::ip::udp::endpoint>();

socket_->async_receive_from(*endpoint,
[this, endpoint](const std::shared_ptr<ecaludp::OwningBuffer>& message, ecaludp::Error& error)
[this, endpoint](const std::shared_ptr<ecaludp::OwningBuffer>& message, const ecaludp::Error& error)
{
if (error)
{
std::cout << "Error sending: " << error.ToString() << std::endl;
std::cerr << "Error sending: " << error.ToString()<< '\n';
socket_->close();
return;
}

{
std::unique_lock<std::mutex> lock(statistics_mutex_);
const std::lock_guard<std::mutex> lock(statistics_mutex_);

bytes_payload_ += message->size();
messages_received_ ++;
Expand Down
6 changes: 6 additions & 0 deletions samples/ecaludp_perftool/src/receiver_npcap_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class ReceiverNpcapAsync : public Receiver
ReceiverNpcapAsync(const ReceiverParameters& parameters);
~ReceiverNpcapAsync() override;

// disable copy and move
ReceiverNpcapAsync(const ReceiverNpcapAsync&) = delete;
ReceiverNpcapAsync(ReceiverNpcapAsync&&) = delete;
ReceiverNpcapAsync& operator=(const ReceiverNpcapAsync&) = delete;
ReceiverNpcapAsync& operator=(ReceiverNpcapAsync&&) = delete;

void start() override;

private:
Expand Down
8 changes: 4 additions & 4 deletions samples/ecaludp_perftool/src/receiver_npcap_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
ReceiverNpcapSync::ReceiverNpcapSync(const ReceiverParameters& parameters)
: Receiver(parameters)
{
std::cout << "Receiver implementation: Synchronous NPCAP" << std::endl;
std::cout << "Receiver implementation: Synchronous NPCAP\n";
}

ReceiverNpcapSync::~ReceiverNpcapSync()
Expand All @@ -55,7 +55,7 @@ void ReceiverNpcapSync::receive_loop()
}
catch (const std::exception& e)
{
std::cerr << "Error creating socket: " << e.what() << std::endl;
std::cerr << "Error creating socket: " << e.what()<< '\n';
exit(1);
}

Expand All @@ -69,12 +69,12 @@ void ReceiverNpcapSync::receive_loop()

if (error)
{
std::cerr << "Error receiving message: " << error.ToString() << std::endl;
std::cerr << "Error receiving message: " << error.ToString()<< '\n';
break;
}

{
std::unique_lock<std::mutex> lock(statistics_mutex_);
const std::lock_guard<std::mutex> lock(statistics_mutex_);

if (is_stopped_)
break;
Expand Down
6 changes: 6 additions & 0 deletions samples/ecaludp_perftool/src/receiver_npcap_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class ReceiverNpcapSync : public Receiver
ReceiverNpcapSync(const ReceiverParameters& parameters);
~ReceiverNpcapSync() override;

// disable copy and move
ReceiverNpcapSync(const ReceiverNpcapSync&) = delete;
ReceiverNpcapSync(ReceiverNpcapSync&&) = delete;
ReceiverNpcapSync& operator=(const ReceiverNpcapSync&) = delete;
ReceiverNpcapSync& operator=(ReceiverNpcapSync&&) = delete;

void start() override;

private:
Expand Down
6 changes: 6 additions & 0 deletions samples/ecaludp_perftool/src/receiver_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class ReceiverSync : public Receiver
ReceiverSync(const ReceiverParameters& parameters);
~ReceiverSync() override;

// disable copy and move
ReceiverSync(const ReceiverSync&) = delete;
ReceiverSync(ReceiverSync&&) = delete;
ReceiverSync& operator=(const ReceiverSync&) = delete;
ReceiverSync& operator=(ReceiverSync&&) = delete;

void start() override;

private:
Expand Down
6 changes: 6 additions & 0 deletions samples/ecaludp_perftool/src/sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class Sender
Sender(const SenderParameters& parameters);
virtual ~Sender();

// disable copy and move
Sender(const Sender&) = delete;
Sender(Sender&&) = delete;
Sender& operator=(const Sender&) = delete;
Sender& operator=(Sender&&) = delete;

virtual void start() = 0;

private:
Expand Down
5 changes: 3 additions & 2 deletions samples/ecaludp_perftool/src/sender_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ SenderAsync::~SenderAsync()
std::cerr << "Error cancelling socket: " << ec.message() << '\n';
}

io_context_thread_->join();
if(io_context_thread_->joinable())
io_context_thread_->join();
}

void SenderAsync::start()
Expand Down Expand Up @@ -78,7 +79,7 @@ void SenderAsync::send_message(const std::shared_ptr<const std::string>& message
{
if (ec)
{
std::cout << "Error sending: " << ec.message() << '\n';
std::cerr << "Error sending: " << ec.message() << '\n';
socket_->close();
return;
}
Expand Down
6 changes: 6 additions & 0 deletions samples/ecaludp_perftool/src/sender_async.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class SenderAsync : public Sender
SenderAsync(const SenderParameters& parameters);
~SenderAsync() override;

// disable copy and move
SenderAsync(const SenderAsync&) = delete;
SenderAsync(SenderAsync&&) = delete;
SenderAsync& operator=(const SenderAsync&) = delete;
SenderAsync& operator=(SenderAsync&&) = delete;

void start() override;

private:
Expand Down
6 changes: 6 additions & 0 deletions samples/ecaludp_perftool/src/sender_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class SenderSync : public Sender
SenderSync(const SenderParameters& parameters);
~SenderSync() override;

// disable copy and move
SenderSync(const SenderSync&) = delete;
SenderSync(SenderSync&&) = delete;
SenderSync& operator=(const SenderSync&) = delete;
SenderSync& operator=(SenderSync&&) = delete;

void start() override;

private:
Expand Down
7 changes: 3 additions & 4 deletions samples/ecaludp_perftool/src/socket_builder_npcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@ namespace SocketBuilderNpcap
// Set receive buffer size
if (parameters.buffer_size > 0)
{
asio::socket_base::receive_buffer_size option(parameters.buffer_size);
bool success = socket->set_receive_buffer_size(parameters.buffer_size);
const bool success = socket->set_receive_buffer_size(parameters.buffer_size);
if (!success)
{
throw std::runtime_error("Failed to set receive buffer size");
}
}

asio::ip::udp::endpoint destination(ip_address, parameters.port);
const asio::ip::udp::endpoint destination(ip_address, parameters.port);

{
bool success = socket->bind(destination);
const bool success = socket->bind(destination);
if (!success)
{
throw std::runtime_error("Failed to bind socket");
Expand Down
2 changes: 1 addition & 1 deletion samples/ecaludp_sample_npcap/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void receive_package()
auto sender_endpoint = std::make_shared<asio::ip::udp::endpoint>();

receive_socket_->async_receive_from(*sender_endpoint
, [sender_endpoint](const std::shared_ptr<ecaludp::OwningBuffer>& buffer, ecaludp::Error& error)
, [sender_endpoint](const std::shared_ptr<ecaludp::OwningBuffer>& buffer, const ecaludp::Error& error)
{
if (error)
{
Expand Down

0 comments on commit f09df3c

Please sign in to comment.