![]() |
Leviathan
0.8.0.0
Leviathan game engine
|
Represents a sent packet and holds all kinds of data for it. More...
#include <SentNetworkThing.h>
Public Types | |
enum | DONE_STATUS { DONE_STATUS::WAITING, DONE_STATUS::DONE, DONE_STATUS::FAILED } |
using | CallbackType = std::function< void(bool, SentNetworkThing &)> |
Public Member Functions | |
DLLEXPORT | SentNetworkThing (uint32_t packetid, uint32_t messagenumber, RECEIVE_GUARANTEE guarantee) |
DLLEXPORT | ~SentNetworkThing () |
bool | IsFinalized () |
Returns true once the packet has been received by the target or lost too many times. More... | |
DLLEXPORT void | OnFinalized (bool succeeded) |
Called by Connection once this is done. More... | |
DLLEXPORT bool | GetStatus () |
Gets the status once IsFinalized returns true blocks otherwise. More... | |
DLLEXPORT void | SetWaitStatus (bool status) |
Sets the status of the wait object notifying all waiters that this has succeeded or failed. More... | |
DLLEXPORT void | SetAsTimed () |
Sets this packet as a timed packet. More... | |
DLLEXPORT void | ResetStartTime () |
Resets the start time. More... | |
DLLEXPORT void | SetCallback (std::shared_ptr< CallbackType > func=nullptr) |
Binds a callback function that is called either when the packet is successfully sent or it times out. More... | |
DLLEXPORT void | SetCallbackFunc (CallbackType func) |
virtual std::string | GetTypeStr ()=0 |
Public Attributes | |
uint32_t | PacketNumber |
Contained in Local packet id. More... | |
const uint32_t | MessageNumber |
RECEIVE_GUARANTEE | Resend = RECEIVE_GUARANTEE::None |
If not RECEIVE_GUARANTEE::None this packet will be resent if considered lost. More... | |
uint8_t | AttemptNumber = 1 |
std::shared_ptr< std::function< void(bool, SentNetworkThing &)> > | Callback |
std::atomic< int64_t > | ConfirmReceiveTime {0} |
The time when this packed got marked as received. More... | |
int64_t | RequestStartTime {0} |
Time this was started. Used to time out this packet and calculate round trip time. More... | |
std::atomic< DONE_STATUS > | IsDone {DONE_STATUS::WAITING} |
Set to true once this object is no longer used. More... | |
Represents a sent packet and holds all kinds of data for it.
Definition at line 14 of file SentNetworkThing.h.
using Leviathan::SentNetworkThing::CallbackType = std::function<void(bool, SentNetworkThing&)> |
Definition at line 23 of file SentNetworkThing.h.
|
strong |
Enumerator | |
---|---|
WAITING | |
DONE | |
FAILED |
Definition at line 16 of file SentNetworkThing.h.
DLLEXPORT Leviathan::SentNetworkThing::SentNetworkThing | ( | uint32_t | packetid, |
uint32_t | messagenumber, | ||
RECEIVE_GUARANTEE | guarantee | ||
) |
Definition at line 12 of file SentNetworkThing.cpp.
|
inline |
Definition at line 28 of file SentNetworkThing.h.
DLLEXPORT bool SentNetworkThing::GetStatus | ( | ) |
Gets the status once IsFinalized returns true blocks otherwise.
Definition at line 49 of file SentNetworkThing.cpp.
|
pure virtual |
Implemented in Leviathan::SentResponse, and Leviathan::SentRequest.
|
inline |
Returns true once the packet has been received by the target or lost too many times.
Definition at line 32 of file SentNetworkThing.h.
DLLEXPORT void Leviathan::SentNetworkThing::OnFinalized | ( | bool | succeeded | ) |
Called by Connection once this is done.
Definition at line 32 of file SentNetworkThing.cpp.
DLLEXPORT void SentNetworkThing::ResetStartTime | ( | ) |
Resets the start time.
Definition at line 18 of file SentNetworkThing.cpp.
DLLEXPORT void SentNetworkThing::SetAsTimed | ( | ) |
Sets this packet as a timed packet.
Definition at line 60 of file SentNetworkThing.cpp.
DLLEXPORT void SentNetworkThing::SetCallback | ( | std::shared_ptr< CallbackType > | func = nullptr | ) |
Binds a callback function that is called either when the packet is successfully sent or it times out.
Definition at line 66 of file SentNetworkThing.cpp.
DLLEXPORT void Leviathan::SentNetworkThing::SetCallbackFunc | ( | CallbackType | func | ) |
Definition at line 71 of file SentNetworkThing.cpp.
DLLEXPORT void SentNetworkThing::SetWaitStatus | ( | bool | status | ) |
Sets the status of the wait object notifying all waiters that this has succeeded or failed.
Will also call the Callback if one is set
Definition at line 24 of file SentNetworkThing.cpp.
uint8_t Leviathan::SentNetworkThing::AttemptNumber = 1 |
Used to detect when a critical packet is lost or if this packet has a specific number of resends
Definition at line 83 of file SentNetworkThing.h.
std::shared_ptr<std::function<void(bool, SentNetworkThing&)> > Leviathan::SentNetworkThing::Callback |
Callback function called when succeeded or failed May only be called by the receiving thread when removing this from the queue. May not be changed after settings to make sure that no race conditions exist
Definition at line 89 of file SentNetworkThing.h.
std::atomic<int64_t> Leviathan::SentNetworkThing::ConfirmReceiveTime {0} |
The time when this packed got marked as received.
This will roughly be the time it took for the packet to reach the destination and return the round-trip time
Definition at line 98 of file SentNetworkThing.h.
std::atomic<DONE_STATUS> Leviathan::SentNetworkThing::IsDone {DONE_STATUS::WAITING} |
Set to true once this object is no longer used.
Definition at line 105 of file SentNetworkThing.h.
const uint32_t Leviathan::SentNetworkThing::MessageNumber |
The ID of the message that was sent (this stays same until this has failed or succeeded)
Definition at line 76 of file SentNetworkThing.h.
uint32_t Leviathan::SentNetworkThing::PacketNumber |
Contained in Local packet id.
Definition at line 72 of file SentNetworkThing.h.
int64_t Leviathan::SentNetworkThing::RequestStartTime {0} |
Time this was started. Used to time out this packet and calculate round trip time.
Definition at line 102 of file SentNetworkThing.h.
RECEIVE_GUARANTEE Leviathan::SentNetworkThing::Resend = RECEIVE_GUARANTEE::None |
If not RECEIVE_GUARANTEE::None this packet will be resent if considered lost.
Definition at line 79 of file SentNetworkThing.h.