43 lines
1.5 KiB
C++
43 lines
1.5 KiB
C++
|
#pragma once
|
||
|
#include "Stream.hpp"
|
||
|
|
||
|
namespace Tesses::Framework::Streams
|
||
|
{
|
||
|
class NetworkStream;
|
||
|
|
||
|
class TcpServer {
|
||
|
int32_t sock;
|
||
|
bool owns;
|
||
|
bool valid;
|
||
|
public:
|
||
|
TcpServer(int32_t sock,bool owns);
|
||
|
TcpServer(uint16_t port, int32_t backlog);
|
||
|
TcpServer(std::string ip, uint16_t port, int32_t backlog);
|
||
|
NetworkStream* GetStream(std::string& ip, uint16_t& port);
|
||
|
~TcpServer();
|
||
|
void Close();
|
||
|
};
|
||
|
class NetworkStream : public Stream {
|
||
|
int32_t sock;
|
||
|
bool owns;
|
||
|
bool success;
|
||
|
bool endOfStream;
|
||
|
public:
|
||
|
bool EndOfStream();
|
||
|
bool CanRead();
|
||
|
bool CanWrite();
|
||
|
NetworkStream(bool ipV6,bool datagram);
|
||
|
NetworkStream(std::string ipOrFqdn, uint16_t port, bool datagram,bool broadcast,bool supportIPv6);
|
||
|
NetworkStream(int32_t sock, bool owns);
|
||
|
void Listen(int32_t backlog);
|
||
|
void Bind(std::string ip, uint16_t port);
|
||
|
void SetBroadcast(bool bC);
|
||
|
NetworkStream* Accept(std::string& ip, uint16_t& port);
|
||
|
size_t Read(uint8_t* buff, size_t sz);
|
||
|
size_t Write(const uint8_t* buff, size_t sz);
|
||
|
size_t ReadFrom(uint8_t* buff, size_t sz, std::string& ip, uint16_t& port);
|
||
|
size_t WriteTo(const uint8_t* buff, size_t sz, std::string ip, uint16_t port);
|
||
|
static std::vector<std::pair<std::string,std::string>> GetIPs(bool ipV6=false);
|
||
|
~NetworkStream();
|
||
|
};
|
||
|
}
|