FeatherMC/src/network/TCPListener.h

43 lines
1016 B
C
Raw Normal View History

2020-07-25 03:01:16 +01:00
#pragma once
2020-07-29 01:46:31 +01:00
#include "Lockable.h"
#include "IListenerInterface.h"
2020-07-25 03:01:16 +01:00
#include <cstdint>
#include <memory>
#include <vector>
namespace Feather::Network
{
2020-07-25 03:01:16 +01:00
class TCPSocket;
class TCPListenerClient;
2020-07-29 01:46:31 +01:00
class TCPClient
{
public:
TCPClient(std::unique_ptr<TCPListenerClient>&& client);
TCPClient(TCPClient&& client);
~TCPClient();
const LockableVector<uint8_t>& GetData() const;
private:
std::unique_ptr<TCPListenerClient> m_client;
};
2020-07-29 15:34:10 +01:00
// TODO: Can we eliminate the move constructor + overloads?
// Kinda unclean.
inline bool operator==(const TCPClient& a, const TCPClient& b) { return &a == &b; }
inline bool operator!=(const TCPClient& a, const TCPClient& b) { return &a != &b; }
2020-07-25 03:01:16 +01:00
class TCPListener
{
public:
2020-07-29 01:46:31 +01:00
TCPListener(uint16_t port, IListenerInterface* callbacks);
2020-07-25 03:01:16 +01:00
~TCPListener();
private:
2020-07-29 01:46:31 +01:00
IListenerInterface* m_callbacks;
2020-07-25 03:01:16 +01:00
std::unique_ptr<TCPSocket> m_socket;
};
}