finish io
All checks were successful
Linux arm64 / Build (push) Successful in 19s

This commit is contained in:
2025-06-27 18:53:03 +02:00
parent 0d26879152
commit ed0b06f78d
11 changed files with 443 additions and 54 deletions

View File

@@ -6,20 +6,7 @@
*/
#include <cstdint>
#include <sp/common/DataBuffer.h>
namespace sp {
namespace option {
struct ZlibCompress {
bool m_Enabled = true;
std::size_t m_CompressionThreshold = 64;
};
} // namespace option
} // namespace sp
#include <sp/io/IOInterface.h>
#include <sp/io/MessageEncapsulator.h>
namespace sp {
namespace zlib {
@@ -41,14 +28,20 @@ DataBuffer Decompress(DataBuffer& buffer, std::uint64_t packetLength);
} // namespace zlib
namespace io {
template <>
class MessageEncapsulator<option::ZlibCompress> {
class ZlibCompress : public MessageEncapsulator {
private:
std::size_t m_CompressionThreshold;
public:
static DataBuffer Encapsulate(const DataBuffer& a_Data, const option::ZlibCompress& a_Option);
static DataBuffer Decapsulate(DataBuffer& a_Data, const option::ZlibCompress& a_Option);
ZlibCompress() : m_CompressionThreshold(64) {}
ZlibCompress(const ZlibCompress&) = default;
virtual ~ZlibCompress() {}
protected:
virtual DataBuffer EncapsulateImpl(const DataBuffer& a_Data) override;
virtual DataBuffer DecapsulateImpl(DataBuffer& a_Data) override;
};
} // namespace io
} // namespace sp
} // namespace sp

View File

@@ -1,6 +1,7 @@
#pragma once
#include <sp/extensions/tcp/TcpSocket.h>
#include <memory>
namespace sp {
namespace io {
@@ -10,7 +11,7 @@ namespace io {
*/
class TcpListener : private NonCopyable {
public:
using SocketHandle = TcpTag::SocketHandle;
using SocketHandle = TcpSocket::SocketHandle;
/**
* \brief Starts listening for guests to connect

View File

@@ -1,14 +1,12 @@
#pragma once
#include <sp/common/NonCopyable.h>
#include <sp/io/IOInterface.h>
#include <sp/io/IoInterface.h>
namespace sp {
namespace io {
struct TcpTag {
using SocketHandle = int;
};
class TcpListener;
class SocketError : public std::exception {
private:
@@ -22,10 +20,9 @@ class SocketError : public std::exception {
}
};
template <>
class IOInterface<TcpTag> : private NonCopyable {
class TcpSocket : public sp::IoInterface {
public:
using SocketHandle = TcpTag::SocketHandle;
using SocketHandle = int;
/**
* \enum Status
@@ -40,14 +37,14 @@ class IOInterface<TcpTag> : private NonCopyable {
Error,
};
IOInterface();
IOInterface(const std::string& a_Host, std::uint16_t a_Port);
IOInterface(IOInterface&& a_Other);
IOInterface& operator=(IOInterface&& a_Other);
virtual ~IOInterface();
TcpSocket();
TcpSocket(const std::string& a_Host, std::uint16_t a_Port);
TcpSocket(TcpSocket&& a_Other);
TcpSocket& operator=(TcpSocket&& a_Other);
virtual ~TcpSocket();
DataBuffer Read(std::size_t a_Amount);
void Write(const sp::DataBuffer& a_Data);
virtual DataBuffer Read(std::size_t a_Amount) override;
virtual void Write(const sp::DataBuffer& a_Data) override;
/**
* \brief Allows to set the socket in non blocking/blocking mode
@@ -79,10 +76,5 @@ class IOInterface<TcpTag> : private NonCopyable {
friend class TcpListener;
};
/**
* \typedef TcpSocket
*/
using TcpSocket = IOInterface<TcpTag>;
} // namespace io
} // namespace sp