Improved UDP functionality and reduced complexity of internal Communications.
This commit is contained in:
@@ -9,7 +9,7 @@ namespace ehs
|
||||
class BaseUDP
|
||||
{
|
||||
protected:
|
||||
AddrType addrType;
|
||||
AddrType type;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
bool bound;
|
||||
@@ -19,7 +19,7 @@ namespace ehs
|
||||
|
||||
BaseUDP();
|
||||
|
||||
BaseUDP(const AddrType addrType);
|
||||
BaseUDP(AddrType type);
|
||||
|
||||
BaseUDP(BaseUDP&& udp) noexcept;
|
||||
|
||||
@@ -31,19 +31,19 @@ namespace ehs
|
||||
|
||||
virtual void Release() = 0;
|
||||
|
||||
virtual void Bind(const Str_8& address, const UInt_16 port) = 0;
|
||||
virtual void Bind(AddrType type, const Str_8& address, UInt_16 port) = 0;
|
||||
|
||||
virtual UInt_64 Send(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size) = 0;
|
||||
virtual UInt_64 Send(AddrType type, const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size) = 0;
|
||||
|
||||
virtual UInt_64 Receive(Str_8* const addr, UInt_16* const port, Byte* const data, const UInt_64 size) = 0;
|
||||
virtual UInt_64 Receive(AddrType* type, Str_8* address, UInt_16* port, Byte* data, UInt_64 size) = 0;
|
||||
|
||||
bool IsBound() const;
|
||||
|
||||
virtual void SetBlocking(const bool blocking) = 0;
|
||||
virtual void SetBlocking(bool blocking) = 0;
|
||||
|
||||
virtual bool IsBlocking() const = 0;
|
||||
|
||||
AddrType GetAddressType() const;
|
||||
AddrType GetLocalAddressType() const;
|
||||
|
||||
Str_8 GetLocalAddress() const;
|
||||
|
||||
|
@@ -21,7 +21,7 @@ namespace ehs
|
||||
private:
|
||||
friend class Endpoint;
|
||||
|
||||
static const Version ver;
|
||||
static const Version version;
|
||||
static const UInt_64 internalSys;
|
||||
static const UInt_64 connectOp;
|
||||
static const UInt_64 connectedOp;
|
||||
@@ -34,16 +34,12 @@ namespace ehs
|
||||
static const UInt_64 latencyOp;
|
||||
static const UInt_64 receivedOp;
|
||||
|
||||
Socket hdl;
|
||||
AddrType type;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
bool bound;
|
||||
UDP udp;
|
||||
Version appVer;
|
||||
EndDisp disposition;
|
||||
bool dropPackets;
|
||||
Str_8 id;
|
||||
UInt_32 hashId;
|
||||
Str_8 id;
|
||||
Byte* buffer;
|
||||
UInt_32 bufferSize;
|
||||
Array<CommsSystem*> systems;
|
||||
@@ -62,7 +58,7 @@ namespace ehs
|
||||
|
||||
Comms();
|
||||
|
||||
Comms(const Version& ver, const EndDisp disposition, const Str_8& id, const UInt_64 maxEndpoints);
|
||||
Comms(const Version& ver, EndDisp disposition, const Str_8& id, UInt_64 maxEndpoints);
|
||||
|
||||
Comms(const Comms& sock);
|
||||
|
||||
@@ -72,43 +68,41 @@ namespace ehs
|
||||
|
||||
void UnInitialize();
|
||||
|
||||
void Bind(const Str_8& newAddress, const UInt_16 newPort);
|
||||
void Bind(AddrType newType, const Str_8& newAddress, UInt_16 newPort);
|
||||
|
||||
void Connect(const Str_8& address, const UInt_16 port);
|
||||
void Connect(AddrType rType, const Str_8& rAddress, UInt_16 rPort);
|
||||
|
||||
bool Disconnect(const EndDisp disposition, const UInt_64 hashId, const Str_8& msg);
|
||||
bool Disconnect(EndDisp endDisp, UInt_64 endHashId, const Str_8& msg);
|
||||
|
||||
bool Disconnect(const EndDisp disposition, const Str_8& id, const Str_8& msg);
|
||||
bool Disconnect(EndDisp endDisp, const Str_8& endId, const Str_8& msg);
|
||||
|
||||
void Broadcast(const EndDisp disposition, const Status status, const bool deltaLocked, const bool encrypted,
|
||||
const bool ensure, const UInt_64 sysHashId, const UInt_64 opHashId,
|
||||
void Broadcast(EndDisp endDisp, Status endStatus, bool deltaLocked, bool encrypted,
|
||||
bool ensure, UInt_64 sysHashId, UInt_64 opHashId,
|
||||
const Serializer<>& payload);
|
||||
|
||||
void Broadcast(const EndDisp disposition, const Status status, const bool deltaLocked, const bool encrypted,
|
||||
const bool ensure, const Str_8& sysId, const Str_8& opId,
|
||||
void Broadcast(EndDisp endDisp, Status endStatus, bool deltaLocked, bool encrypted,
|
||||
bool ensure, const Str_8& sysId, const Str_8& opId,
|
||||
const Serializer<>& payload);
|
||||
|
||||
void Poll();
|
||||
|
||||
bool IsInitialized() const;
|
||||
|
||||
void SetAddressType(const AddrType newType);
|
||||
AddrType GetLocalAddressType() const;
|
||||
|
||||
AddrType GetAddressType() const;
|
||||
Str_8 GetLocalAddress() const;
|
||||
|
||||
Str_8 GetAddress() const;
|
||||
|
||||
UInt_16 GetPort() const;
|
||||
UInt_16 GetLocalPort() const;
|
||||
|
||||
bool IsBound() const;
|
||||
|
||||
Version GetVersion() const;
|
||||
static Version GetVersion();
|
||||
|
||||
Version GetAppVersion() const;
|
||||
|
||||
EndDisp GetDisposition() const;
|
||||
|
||||
void EnableDropPackets(const bool enable);
|
||||
void EnableDropPackets(bool enable);
|
||||
|
||||
bool IsDropPacketsEnabled() const;
|
||||
|
||||
@@ -116,55 +110,55 @@ namespace ehs
|
||||
|
||||
UInt_64 GetHashId() const;
|
||||
|
||||
bool HasSystem(const UInt_64 hashId) const;
|
||||
bool HasSystem(UInt_64 sysHashId) const;
|
||||
|
||||
bool HasSystem(const Str_8& id) const;
|
||||
bool HasSystem(const Str_8& sysId) const;
|
||||
|
||||
bool AddSystem(CommsSystem* sys);
|
||||
|
||||
CommsSystem* GetSystem(const UInt_64 hashId);
|
||||
CommsSystem* GetSystem(UInt_64 sysHashId);
|
||||
|
||||
CommsSystem* GetSystem(const Str_8& id);
|
||||
CommsSystem* GetSystem(const Str_8& sysId);
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const Status status, const UInt_64 hashId) const;
|
||||
bool HasEndpoint(EndDisp endDisp, Status endStatus, UInt_64 endHashId) const;
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const Status status, const Str_8& id) const;
|
||||
bool HasEndpoint(EndDisp endDisp, Status endStatus, const Str_8& endId) const;
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const UInt_64 hashId) const;
|
||||
bool HasEndpoint(EndDisp endDisp, UInt_64 endHashId) const;
|
||||
|
||||
bool HasEndpoint(const EndDisp disposition, const Str_8& id) const;
|
||||
bool HasEndpoint(EndDisp endDisp, const Str_8& endId) const;
|
||||
|
||||
bool HasEndpoint(const Str_8& address, const UInt_16 port) const;
|
||||
bool HasEndpoint(const Str_8& rAddress, UInt_16 rPort) const;
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const Status status, const UInt_64 hashId);
|
||||
Endpoint* GetEndpoint(EndDisp endDisp, Status endStatus, UInt_64 endHashId);
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const Status status, const Str_8& id);
|
||||
Endpoint* GetEndpoint(EndDisp endDisp, Status endStatus, const Str_8& endId);
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const UInt_64 hashId);
|
||||
Endpoint* GetEndpoint(EndDisp endDisp, UInt_64 endHashId);
|
||||
|
||||
Endpoint* GetEndpoint(const EndDisp disposition, const Str_8& id);
|
||||
Endpoint* GetEndpoint(EndDisp endDisp, const Str_8& endId);
|
||||
|
||||
Endpoint* GetEndpoint(const Str_8& address, const UInt_16 port);
|
||||
Endpoint* GetEndpoint(const Str_8& rAddress, UInt_16 rPort);
|
||||
|
||||
Array<Endpoint*> GetEndpoints(const EndDisp disposition, const Status status);
|
||||
Array<Endpoint*> GetEndpoints(EndDisp endDisp, Status endStatus);
|
||||
|
||||
Array<Endpoint*> GetEndpoints(const EndDisp disposition);
|
||||
Array<Endpoint*> GetEndpoints(EndDisp endDisp);
|
||||
|
||||
UInt_64 GetEndpointsCount(const EndDisp disposition, const Status status);
|
||||
UInt_64 GetEndpointsCount(EndDisp endDisp, Status endStatus);
|
||||
|
||||
UInt_64 GetEndpointsCount(const EndDisp disposition);
|
||||
UInt_64 GetEndpointsCount(EndDisp endDisp);
|
||||
|
||||
UInt_64 GetMaxEndpoints() const;
|
||||
|
||||
void SetBlocking(const bool blocking);
|
||||
void SetBlocking(bool blocking);
|
||||
|
||||
bool IsBlocking() const;
|
||||
|
||||
void SetMaxTimeout(const float seconds);
|
||||
void SetMaxTimeout(float seconds);
|
||||
|
||||
float GetMaxTimeout() const;
|
||||
|
||||
void SetResendRate(const float seconds);
|
||||
void SetResendRate(float seconds);
|
||||
|
||||
float GetResendRate() const;
|
||||
|
||||
@@ -179,18 +173,12 @@ namespace ehs
|
||||
|
||||
void UpdateQueue();
|
||||
|
||||
bool RemoveEndpoint(const EndDisp disposition, const UInt_64 hashId);
|
||||
bool RemoveEndpoint(EndDisp disposition, UInt_64 hashId);
|
||||
|
||||
bool RemoveEndpoint(const Str_8& address, const UInt_16 port);
|
||||
bool RemoveEndpoint(const Str_8& address, UInt_16 port);
|
||||
|
||||
bool RemoveEndpoint(const Endpoint* const end);
|
||||
bool RemoveEndpoint(const Endpoint* end);
|
||||
|
||||
void PollEndpoints(Vector<Endpoint*>& endpoints);
|
||||
|
||||
void Bind_v6(const Str_8& address, const UInt_16 port);
|
||||
|
||||
void Bind_v4(const Str_8& address, const UInt_16 port);
|
||||
|
||||
UInt_16 Receive(Str_8* address, UInt_16* port, Byte* const data, const UInt_16 size);
|
||||
void PollEndpoints();
|
||||
};
|
||||
}
|
@@ -27,6 +27,7 @@ namespace ehs
|
||||
Vector<Insurance> sent;
|
||||
UInt_64 nextRecvId;
|
||||
Vector<Fragments> received;
|
||||
AddrType type;
|
||||
Str_8 address;
|
||||
UInt_16 port;
|
||||
float deltaDuration;
|
||||
@@ -40,20 +41,20 @@ namespace ehs
|
||||
public:
|
||||
Endpoint();
|
||||
|
||||
Endpoint(Comms* owner, const EndDisp disposition, const Architecture arch, const Str_8& id,
|
||||
const AddrType& type, const Str_8& address, const UInt_16 port);
|
||||
Endpoint(Comms* owner, EndDisp disposition, Architecture arch, Str_8 id,
|
||||
AddrType type, Str_8 address, UInt_16 port);
|
||||
|
||||
Endpoint(Comms* owner, const AddrType& type, const Str_8& address, const UInt_16 port);
|
||||
Endpoint(Comms* owner, AddrType type, Str_8 address, UInt_16 port);
|
||||
|
||||
Endpoint(const Endpoint& end);
|
||||
|
||||
Endpoint& operator=(const Endpoint& end);
|
||||
|
||||
void Poll(const float delta);
|
||||
void Poll(float delta);
|
||||
|
||||
EndDisp GetDisposition() const;
|
||||
|
||||
void SetStatus(const Status newStatus);
|
||||
void SetStatus(Status newStatus);
|
||||
|
||||
Status GetStatus() const;
|
||||
|
||||
@@ -72,8 +73,7 @@ namespace ehs
|
||||
/// @param [in] sys The system hash id to execute an operation from.
|
||||
/// @param [in] op The operation hash id in the system to execute.
|
||||
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
||||
void Send(const bool deltaLocked, const bool encrypted, const bool ensure, const UInt_64 sys,
|
||||
const UInt_64 op, const Serializer<>& payload);
|
||||
void Send(bool deltaLocked, bool encrypted, bool ensure, UInt_64 sys, UInt_64 op, const Serializer<UInt_64>& payload);
|
||||
|
||||
/// Sends data to the remote endpoint.
|
||||
/// @param [in] deltaLocked Whether or not to match the remote endpoint's delta time to prevent overloading the client. This will drop data if delta time does not match.
|
||||
@@ -82,10 +82,9 @@ namespace ehs
|
||||
/// @param [in] sys The system string id to execute an operation from.
|
||||
/// @param [in] op The operation string id in the system to execute.
|
||||
/// @param [in] payload Additional parameters and data to send to the remote endpoint.
|
||||
void Send(const bool deltaLocked, const bool encrypted, const bool ensure, const Str_8& sys,
|
||||
const Str_8& op, const Serializer<>& payload);
|
||||
void Send(bool deltaLocked, bool encrypted, bool ensure, const Str_8& sys, const Str_8& op, const Serializer<UInt_64>& payload);
|
||||
|
||||
void RemoveInsurance(const UInt_64 msgId, const UInt_64 fragment);
|
||||
void RemoveInsurance(UInt_64 msgId, UInt_64 fragment);
|
||||
|
||||
UInt_64 GetNextRecvId() const;
|
||||
|
||||
@@ -99,7 +98,7 @@ namespace ehs
|
||||
|
||||
UInt_16 GetPort() const;
|
||||
|
||||
void SetDeltaRate(const float newDeltaRate);
|
||||
void SetDeltaRate(float newDeltaRate);
|
||||
|
||||
float GetDeltaRate() const;
|
||||
|
||||
@@ -107,17 +106,17 @@ namespace ehs
|
||||
|
||||
float GetLastPing() const;
|
||||
|
||||
void Ping(const float delta);
|
||||
void Ping(float delta);
|
||||
|
||||
void Pong(const float delta);
|
||||
void Pong(float delta);
|
||||
|
||||
void SendLatency();
|
||||
|
||||
void SetLatency(const float newLatency);
|
||||
void SetLatency(float newLatency);
|
||||
|
||||
float GetLatency() const;
|
||||
|
||||
void SetQueueSlot(const UInt_64 slot);
|
||||
void SetQueueSlot(UInt_64 slot);
|
||||
|
||||
UInt_64 GetQueueSlot() const;
|
||||
|
||||
@@ -129,9 +128,5 @@ namespace ehs
|
||||
bool SortingNeeded() const;
|
||||
|
||||
void SortReceived();
|
||||
|
||||
UInt_16 Send_v6(const Serializer<>& payload);
|
||||
|
||||
UInt_16 Send_v4(const Serializer<>& payload);
|
||||
};
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ namespace ehs
|
||||
UDP();
|
||||
|
||||
/// Default members initialization.
|
||||
UDP(const AddrType addrType);
|
||||
UDP(AddrType type);
|
||||
|
||||
UDP(UDP&& udp) noexcept;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace ehs
|
||||
/// @param [in] address The local IPv4 or IPv6 address to bind to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
/// @param [in] port The port to bind to.
|
||||
/// @note Requires the port given to be forwarded if this is called.
|
||||
void Bind(const Str_8& address, const UInt_16 port) override;
|
||||
void Bind(AddrType type, const Str_8& address, UInt_16 port) override;
|
||||
|
||||
/// Sends data using a C-style byte array.
|
||||
/// @param [in] addr The remote Ipv4 or Ipv6 address to send to. Resolves domain names. The given address can be empty, "127.0.0.1", or "localhost" to automatically find the appropriate device.
|
||||
@@ -49,7 +49,7 @@ namespace ehs
|
||||
/// @param [in] data The C-style byte array to send.
|
||||
/// @param [in] size The size of the C-style byte array.
|
||||
/// @note The size of data to be sent cannot exceed "UDP::maxPayloadIpv4" or "UDP::maxPayloadIpv6".
|
||||
UInt_64 Send(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size) override;
|
||||
UInt_64 Send(AddrType type, const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size) override;
|
||||
|
||||
/// Receives data using the packet helper class.
|
||||
/// @param [out] addr The Ipv4 or Ipv6 address of the sender.
|
||||
@@ -58,11 +58,11 @@ namespace ehs
|
||||
/// @param [in] size The size of the pre-allocated C-style byte array.
|
||||
/// @returns The size of the data received.
|
||||
/// @warning The provided C-style byte array must be freed when finished using.
|
||||
UInt_64 Receive(Str_8* const addr, UInt_16* const port, Byte* const data, const UInt_64 size) override;
|
||||
UInt_64 Receive(AddrType* type, Str_8* address, UInt_16* port, Byte* data, UInt_64 size) override;
|
||||
|
||||
/// Sets whether or not receiving data blocks the next task.
|
||||
/// @param [in] blocking Whether or not to block.
|
||||
void SetBlocking(const bool blocking) override;
|
||||
void SetBlocking(bool blocking) override;
|
||||
|
||||
/// Retrieves whether or not this socket will block when receiving data.
|
||||
/// @returns The result.
|
||||
@@ -71,12 +71,12 @@ namespace ehs
|
||||
bool IsValid() const override;
|
||||
|
||||
private:
|
||||
void Bind_v6(const Str_8& address, const UInt_16 port);
|
||||
void Bind_v6(const Str_8& address, UInt_16 port) const;
|
||||
|
||||
void Bind_v4(const Str_8& address, const UInt_16 port);
|
||||
void Bind_v4(const Str_8& address, UInt_16 port) const;
|
||||
|
||||
UInt_64 Send_v6(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size);
|
||||
UInt_64 Send_v6(const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size);
|
||||
|
||||
UInt_64 Send_v4(const Str_8& addr, const UInt_16 port, const Byte* const data, const UInt_64 size);
|
||||
UInt_64 Send_v4(const Str_8& address, UInt_16 port, const Byte* data, UInt_64 size);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user