EHS
Loading...
Searching...
No Matches
BaseTCP.h
Go to the documentation of this file.
1#pragma once
2
3#include "ehs/EHS.h"
4#include "ehs/Str.h"
5#include "Request.h"
6#include "Response.h"
7
8#include "Socket.h"
9
10namespace ehs
11{
12 class EHS_LIB_IO BaseTCP
13 {
14 protected:
22 bool bound;
25
26 public:
27 static const UInt_16 HTTPS_Port = 443;
28 static const UInt_16 HTTP_Port = 80;
29 static const UInt_16 MaxHeaderSize = 8192;
30
31 virtual ~BaseTCP() = default;
32
34 BaseTCP();
35
38 BaseTCP(IP ip);
39
40 BaseTCP(BaseTCP&& tcp) noexcept;
41
42 BaseTCP(const BaseTCP& tcp);
43
44 BaseTCP& operator=(BaseTCP&& tcp) noexcept;
45
46 BaseTCP& operator=(const BaseTCP& tcp);
47
49 virtual void Initialize() = 0;
50
52 virtual void Release() = 0;
53
58 virtual void Bind(const Str_8& address, UInt_16 port) = 0;
59
62 virtual void Listen() = 0;
63
66 virtual BaseTCP* Accept() = 0;
67
72 virtual void Connect(const Str_8& address, UInt_16 port) = 0;
73
77 virtual UInt_64 Send(const Byte* buffer, UInt_32 size) = 0;
78
83 virtual UInt_64 Receive(Byte* buffer, UInt_32 size) = 0;
84
87 void SendStr(const Str_8& str);
88
91 void SendRes(const Response& res);
92
95 void SendReq(Request& req);
96
100
104
107 IP GetAddressType() const;
108
111 Str_8 GetLocalAddress() const;
112
115 unsigned short GetLocalPort() const;
116
119 Str_8 GetRemoteAddress() const;
120
123 UInt_16 GetRemotePort() const;
124
127 bool IsConnection() const;
128
131 bool IsBound() const;
132
135 bool IsListening() const;
136
139 bool IsConnected() const;
140
143 virtual void SetBlocking(bool blocking) = 0;
144
147 virtual bool IsBlocking() const = 0;
148
149 virtual void SetIPv6Only(bool value) = 0;
150
151 virtual bool IsIPv6Only() const = 0;
152
155 virtual bool IsValid() const = 0;
156
157 private:
158 Str_8 RecvHeader();
159
160 Str_8 RecvBody(UInt_64 contentLength);
161
162 UInt_64 RecvChunkSize();
163
164 Str_8 RecvChunk(UInt_64 chunkSize);
165 };
166}
Str_8 remoteHostName
Definition BaseTCP.h:18
UInt_16 GetRemotePort() const
Definition BaseTCP.cpp:211
UInt_16 localPort
Definition BaseTCP.h:17
virtual void Initialize()=0
Explicitly initialize the socket.
bool listening
Definition BaseTCP.h:23
void SendRes(const Response &res)
Definition BaseTCP.cpp:98
virtual void Release()=0
Explicitly release resources before it falls off the stack.
void SendReq(Request &req)
Definition BaseTCP.cpp:106
virtual UInt_64 Receive(Byte *buffer, UInt_32 size)=0
IP GetAddressType() const
Definition BaseTCP.cpp:191
bool IsConnected() const
Definition BaseTCP.cpp:231
Str_8 localAddr
Definition BaseTCP.h:16
static const UInt_16 MaxHeaderSize
Definition BaseTCP.h:29
virtual void Listen()=0
BaseTCP()
Initializes the socket with the defaults.
Definition BaseTCP.cpp:6
bool IsListening() const
Definition BaseTCP.cpp:226
Str_8 GetRemoteAddress() const
Definition BaseTCP.cpp:206
BaseTCP & operator=(BaseTCP &&tcp) noexcept
Definition BaseTCP.cpp:31
virtual bool IsIPv6Only() const =0
bool connected
Definition BaseTCP.h:24
Response RecvRes()
Definition BaseTCP.cpp:116
void SendStr(const Str_8 &str)
Definition BaseTCP.cpp:77
virtual bool IsBlocking() const =0
virtual void Bind(const Str_8 &address, UInt_16 port)=0
bool IsBound() const
Definition BaseTCP.cpp:221
Request RecvReq()
Definition BaseTCP.cpp:152
bool IsConnection() const
Definition BaseTCP.cpp:216
bool bound
Definition BaseTCP.h:22
static const UInt_16 HTTPS_Port
Definition BaseTCP.h:27
virtual bool IsValid() const =0
virtual void SetBlocking(bool blocking)=0
IP ip
Definition BaseTCP.h:15
bool connection
Definition BaseTCP.h:21
unsigned short GetLocalPort() const
Definition BaseTCP.cpp:201
UInt_16 remotePort
Definition BaseTCP.h:20
virtual void Connect(const Str_8 &address, UInt_16 port)=0
virtual ~BaseTCP()=default
Str_8 GetLocalAddress() const
Definition BaseTCP.cpp:196
static const UInt_16 HTTP_Port
Definition BaseTCP.h:28
virtual UInt_64 Send(const Byte *buffer, UInt_32 size)=0
virtual BaseTCP * Accept()=0
virtual void SetIPv6Only(bool value)=0
Str_8 remoteAddr
Definition BaseTCP.h:19
Definition Request.h:20
Definition Response.h:12
Definition Anchor.h:6
unsigned int UInt_32
Definition Types.h:49
IP
Definition Socket.h:29
Str< Char_8, UInt_64 > Str_8
Definition Str.h:1902
unsigned char Byte
Definition Types.h:39
unsigned short UInt_16
Definition Types.h:46