Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up debug connection information #142

Merged
merged 1 commit into from
Dec 13, 2024
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
19 changes: 9 additions & 10 deletions libs/base/src/ecflow/base/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,33 @@

connection::~connection() {
#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: Connection::~connection socket_.is_open() = " << socket_.is_open() << "\n\n";
else
std::cout << "CLIENT: Connection::~connection socket_.is_open() = " << socket_.is_open() << "\n\n";
auto is_socket_open = socket_.is_open();
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": Connection::~connection socket_.is_open() = " << is_socket_open << "\n\n";
#endif
}

connection::connection(boost::asio::io_context& io) : socket_(io) {
#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: Connection::connection\n";
else
std::cout << "CLIENT: Connection::connection\n";
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": Connection::connection\n";
#endif
}

void connection::log_error(const char* msg) {
const char* in_context = ", in client";
if (Ecf::server())
if (Ecf::server()) {
in_context = ", in server";
}
ecf::LogToCout logToCout;
LOG(ecf::Log::ERR, msg << in_context);
}

void connection::log_archive_error(const char* msg, const std::exception& ae, const std::string& data) {
const char* in_context = ", in client";
if (Ecf::server())
if (Ecf::server()) {
in_context = ", in server";
}
ecf::LogToCout logToCout;
LOG(ecf::Log::ERR, msg << ae.what() << in_context << " data:\n" << data);
}
43 changes: 17 additions & 26 deletions libs/base/src/ecflow/base/Connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ class connection {
void async_write(const T& t, Handler handler) {

#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: Connection::async_write\n";
else
std::cout << "CLIENT: Connection::async_write\n";
std::cout << " Serialise the data first so we know how large it is\n";
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": Connection::async_write\n"
<< " Serialise the data first so we know how large it is\n";
#endif
// Serialise the data first so we know how large it is.
try {
Expand Down Expand Up @@ -86,11 +84,11 @@ class connection {
outbound_header_ = header_stream.str();

#ifdef DEBUG_CONNECTION
std::cout << " Write the HEADER and serialised DATA to the socket\n";
std::cout << " outbound_header_.size(" << outbound_header_.size() << ")\n";
std::cout << " outbound_header_:'" << outbound_header_ << "' # this is the size in hex\n";
std::cout << " outbound_data_.size(" << outbound_data_.size() << ")\n";
std::cout << " hdr+data:'" << outbound_header_ << outbound_data_ << "'\n";
std::cout << " Write the HEADER and serialised DATA to the socket\n"
<< " outbound_header_.size(" << outbound_header_.size() << ")\n"
<< " outbound_header_:'" << outbound_header_ << "' # this is the size in hex\n"
<< " outbound_data_.size(" << outbound_data_.size() << ")\n"
<< " hdr+data:'" << outbound_header_ << outbound_data_ << "'\n";
#endif
// Write the serialized data to the socket. We use "gather-write" to send
// both the header and the data in a single write operation.
Expand All @@ -113,10 +111,8 @@ class connection {
void async_read(T& t, Handler handler) {

#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: Connection::async_read\n";
else
std::cout << "CLIENT: Connection::async_read\n";
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": Connection::async_read\n";
#endif

// Issue a read operation to read exactly the number of bytes in a header
Expand All @@ -133,11 +129,9 @@ class connection {
template <typename T, typename Handler>
void handle_read_header(const boost::system::error_code& e, T& t, Handler handler) {
#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: Connection::handle_read_header\n";
else
std::cout << "CLIENT: Connection::handle_read_header\n";
std::cout << " header:'" << std::string(inbound_header_, header_length)
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": Connection::handle_read_header\n"
<< " header:'" << std::string(inbound_header_, header_length)
<< "' # this size of payload in hex\n";
#endif
if (e) {
Expand Down Expand Up @@ -172,10 +166,8 @@ class connection {
template <typename T, typename Handler>
void handle_read_data(const boost::system::error_code& e, T& t, Handler handler) {
#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: Connection::handle_read_data\n";
else
std::cout << "CLIENT: Connection::handle_read_data\n";
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": Connection::handle_read_data\n";
#endif

if (e) {
Expand All @@ -186,9 +178,8 @@ class connection {
std::string archive_data(&inbound_data_[0], inbound_data_.size());
try {
#ifdef DEBUG_CONNECTION
std::cout << " inbound_data_.size(" << inbound_data_.size() << ") typeid(" << typeid(t).name()
<< ")\n";
std::cout << " '" << archive_data << "'\n";
std::cout << " inbound_data_.size(" << inbound_data_.size() << ") typeid=" << typeid(t).name() << "\n"
<< " '" << archive_data << "'\n";
#endif
ecf::restore_from_string(archive_data, t);
}
Expand Down
22 changes: 10 additions & 12 deletions libs/base/src/ecflow/base/ssl_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@

ssl_connection::~ssl_connection() {
#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: ssl_connection::~ssl_connection socket_.is_open() = " << socket_.is_open() << "\n\n";
else
std::cout << "CLIENT: ssl_connection::~ssl_connection socket_.is_open() = " << socket_.is_open() << "\n\n";
auto is_socket_open = socket_.lowest_layer().is_open();
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": ssl_connection::~ssl_connection socket_.is_open() = " << is_socket_open << "\n\n";
#endif
}

ssl_connection::ssl_connection(boost::asio::io_context& io, boost::asio::ssl::context& context)
: socket_(io, context) {
ssl_connection::ssl_connection(boost::asio::io_context& io, boost::asio::ssl::context& context) : socket_(io, context) {
#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: ssl_connection::ssl_connection\n";
else
std::cout << "CLIENT: ssl_connection::ssl_connection\n";
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": ssl_connection::ssl_connection\n";
#endif
socket_.set_verify_mode(boost::asio::ssl::verify_peer);

Expand Down Expand Up @@ -61,16 +57,18 @@ bool ssl_connection::verify_certificate(bool preverified, boost::asio::ssl::veri

void ssl_connection::log_error(const char* msg) {
const char* in_context = ", in client";
if (Ecf::server())
if (Ecf::server()) {
in_context = ", in server";
}
ecf::LogToCout logToCout;
LOG(ecf::Log::ERR, msg << in_context);
}

void ssl_connection::log_archive_error(const char* msg, const std::exception& ae, const std::string& data) {
const char* in_context = ", in client";
if (Ecf::server())
if (Ecf::server()) {
in_context = ", in server";
}
ecf::LogToCout logToCout;
LOG(ecf::Log::ERR, msg << ae.what() << in_context << " data:\n" << data);
}
44 changes: 18 additions & 26 deletions libs/base/src/ecflow/base/ssl_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ class ssl_connection {
void async_write(const T& t, Handler handler) {

#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: ssl_connection::async_write\n";
else
std::cout << "CLIENT: ssl_connection::async_write\n";
std::cout << " Serialise the data first so we know how large it is\n";
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": ssl_connection::async_write\n"
<< " Serialise the data first so we know how large it is\n";
#endif
// Serialise the data first so we know how large it is.
try {
Expand Down Expand Up @@ -96,11 +94,11 @@ class ssl_connection {
outbound_header_ = header_stream.str();

#ifdef DEBUG_CONNECTION
std::cout << " Write the HEADER and serialised DATA to the socket\n";
std::cout << " outbound_header_.size(" << outbound_header_.size() << ")\n";
std::cout << " outbound_header_:'" << outbound_header_ << "' # this is the size in hex\n";
std::cout << " outbound_data_.size(" << outbound_data_.size() << ")\n";
std::cout << " hdr+data:'" << outbound_header_ << outbound_data_ << "'\n";
std::cout << " Write the HEADER and serialised DATA to the socket\n"
<< " outbound_header_.size(" << outbound_header_.size() << ")\n"
<< " outbound_header_:'" << outbound_header_ << "' # this is the size in hex\n"
<< " outbound_data_.size(" << outbound_data_.size() << ")\n"
<< " hdr+data:'" << outbound_header_ << outbound_data_ << "'\n";
#endif

// Write the serialized data to the socket. We use "gather-write" to send
Expand All @@ -124,10 +122,8 @@ class ssl_connection {
void async_read(T& t, Handler handler) {

#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: ssl_connection::async_read\n";
else
std::cout << "CLIENT: ssl_connection::async_read\n";
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": ssl_connection::async_read\n";
#endif

// Issue a read operation to read exactly the number of bytes in a header.
Expand All @@ -144,11 +140,9 @@ class ssl_connection {
template <typename T, typename Handler>
void handle_read_header(const boost::system::error_code& e, T& t, Handler handler) {
#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: ssl_onnection::handle_read_header\n";
else
std::cout << "CLIENT: ssl_connection::handle_read_header\n";
std::cout << " header:'" << std::string(inbound_header_, header_length)
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": ssl_connection::handle_read_header\n"
<< " header:'" << std::string(inbound_header_, header_length)
<< "' # this size of payload in hex\n";
#endif
if (e) {
Expand Down Expand Up @@ -183,10 +177,8 @@ class ssl_connection {
template <typename T, typename Handler>
void handle_read_data(const boost::system::error_code& e, T& t, Handler handler) {
#ifdef DEBUG_CONNECTION
if (Ecf::server())
std::cout << "SERVER: ssl_connection::handle_read_data\n";
else
std::cout << "CLIENT: ssl_connection::handle_read_data\n";
auto location = Ecf::server() ? "SERVER" : "CLIENT";
std::cout << location << ": ssl_connection::handle_read_data\n";
#endif

if (e) {
Expand All @@ -197,9 +189,9 @@ class ssl_connection {
std::string archive_data(&inbound_data_[0], inbound_data_.size());
try {
#ifdef DEBUG_CONNECTION
std::cout << " inbound_data_.size(" << inbound_data_.size() << ") typeid(" << typeid(t).name()
<< ")\n";
std::cout << " '" << archive_data << "'\n";
auto tname = typeid(t).name();
std::cout << " inbound_data_.size(" << inbound_data_.size() << ") typeid=" << tname << "\n"
<< " '" << archive_data << "'\n";
#endif
ecf::restore_from_string(archive_data, t);
}
Expand Down
Loading