diff options
Diffstat (limited to 'src/blu_cat/net/common/connection.cpp')
-rw-r--r-- | src/blu_cat/net/common/connection.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/blu_cat/net/common/connection.cpp b/src/blu_cat/net/common/connection.cpp index b4e8f1b..643d30c 100644 --- a/src/blu_cat/net/common/connection.cpp +++ b/src/blu_cat/net/common/connection.cpp @@ -46,7 +46,7 @@ Connection::read_header() else { std::cout << "Failed to read header: " << error.message() << std::endl; - this->connection_callback->end_connection(this->index); + this->connection_callback->disconnect(this->index); } }); } @@ -67,7 +67,7 @@ Connection::read_body() else { std::cout << "Failed to read body." << std::endl; - this->connection_callback->end_connection(this->index); + this->connection_callback->disconnect(this->index); } }); } @@ -96,7 +96,7 @@ Connection::send(const uint32_t id, const std::vector<uint8_t> &msg) { std::cout << "Failed to send message: " << error.message() << std::endl; - this->connection_callback->end_connection(this->index); + this->connection_callback->disconnect(this->index); } delete buffered_msg; }); @@ -104,20 +104,19 @@ Connection::send(const uint32_t id, const std::vector<uint8_t> &msg) return true; } -void -Connection::read_messages() +bool +Connection::read_message(Message *m) { - while(this->messages.size() > 0) - this->message_callback->read_message( - std::move(this->messages.pop_back())); + if(this->messages.size() <= 0) return false; + + *m = std::move(this->messages.pop_back()); + return true; } Connection::Connection( - MessageCallback *message_callback, ConnectionCallback *connection_callback, asio::io_context &io_context, asio::ip::tcp::socket socket, unsigned long index): - message_callback{message_callback}, connection_callback{connection_callback}, io_context{io_context}, socket{std::move(socket)}, @@ -128,8 +127,6 @@ Connection::Connection( Connection::~Connection() { - this->message_callback->disconnect(); - delete message_callback; this->socket.close(); } |