Core/Network: Socket refactors

* Devirtualize calls to Read and Update by marking concrete implementations as final
* Removed derived class template argument
* Specialize boost::asio::basic_stream_socket for boost::asio::io_context instead of type-erased any_io_executor
* Make socket initialization easier composable (before entering Read loop)
* Remove use of deprecated boost::asio::null_buffers and boost::beast::ssl_stream
This commit is contained in:
Shauren
2025-04-08 19:15:16 +02:00
parent 40d80f3476
commit e8b2be3527
32 changed files with 967 additions and 811 deletions

View File

@@ -29,9 +29,11 @@
void RASession::Start()
{
_socket.non_blocking(false);
// wait 1 second for active connections to send negotiation request
for (int counter = 0; counter < 10 && _socket.available() == 0; counter++)
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::this_thread::sleep_for(100ms);
// Check if there are bytes available, if they are, then the client is requesting the negotiation
if (_socket.available() > 0)

View File

@@ -15,10 +15,11 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RASESSION_H__
#define __RASESSION_H__
#ifndef TRINITYCORE_RA_SESSION_H
#define TRINITYCORE_RA_SESSION_H
#include "Define.h"
#include "Socket.h"
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/streambuf.hpp>
#include <future>
@@ -29,7 +30,7 @@ const size_t bufferSize = 4096;
class RASession : public std::enable_shared_from_this <RASession>
{
public:
RASession(boost::asio::ip::tcp::socket&& socket) : _socket(std::move(socket)), _commandExecuting(nullptr)
RASession(Trinity::Net::IoContextTcpSocket&& socket) : _socket(std::move(socket)), _commandExecuting(nullptr)
{
}
@@ -47,7 +48,7 @@ private:
static void CommandPrint(void* callbackArg, std::string_view text);
static void CommandFinished(void* callbackArg, bool);
boost::asio::ip::tcp::socket _socket;
Trinity::Net::IoContextTcpSocket _socket;
boost::asio::streambuf _readBuffer;
boost::asio::streambuf _writeBuffer;
std::promise<void>* _commandExecuting;