UDP クライアントイベント - OnPing

OnPingは、Diarkis サーバクラスターに対するPing要求への応答を受信したときに呼び出されます。Diarkis サーバクラスターとの「接続を確認」や「応答速度を計測」する際にPing()を呼びます。またPing応答はUDPを使用するため、パケットロスする可能性があります。

DiarkisUdpBase.h

class DIARKIS_API DiarkisUdpBase
{
protected:
 void OnConnect(bool isReconnect);
void OnConnect(bool isReconnect);
void OnDisconnect(bool isReconnect);
void OnResponse(const DiarkisResponseEventArgs& args, DiarkisTransportType tt);
void OnPush(const DiarkisPushEventArgs& args, DiarkisTransportType tt);
void OnEcho(const DiarkisUdpEchoEventArgs& args);
void OnPing(const DiarkisUdpPingEventArgs& args);

std::vector<std::function<void()>> eventUnsubscriptions;
}

DiarkisUdpBase.cpp

#define REG_EVENT(__EVENT__, __LAMBDA__) this->eventUnsubscriptions.push_back(__EVENT__->Register(__LAMBDA__))


void DiarkisUdpBase::Setup(std::shared_ptr<LoggerFactory> loggerFactory, std::shared_ptr<ILoggerBackend> loggerBackend)
{
if (this->udp == nullptr)
{
this->udp.reset(DiarkisCreateUdp(200, 5000));
}

this->udp->SetLoggerFactory(loggerFactory);
this->fileAndDebugLoggerBackend = loggerBackend;

REG_EVENT(this->udp->GetConnectedEvent(), [this](void*, bool reconnect) { this->OnConnect(reconnect); });
REG_EVENT(this->udp->GetDisconnectedEvent(), [this](void*, bool reconnect) { this->OnDisconnect(reconnect); });
REG_EVENT(this->udp->GetResponseEvent(), [this](void*, const DiarkisResponseEventArgs& args) { this->OnResponse(args, DiarkisTransportType::UDP); });
REG_EVENT(this->udp->GetPushEvent(), [this](void*, const DiarkisPushEventArgs& args) { this->OnPush(args, DiarkisTransportType::UDP); });
REG_EVENT(this->udp->GetEchoEvent(), [this](void*, const DiarkisUdpEchoEventArgs& args) { this->OnEcho(args); });
REG_EVENT(this->udp->GetPingEvent(), [this](void*, const DiarkisUdpPingEventArgs& args) { this->OnPing(args); });

}

void DiarkisUdpBase::SendPing(const DiarkisUdpPingEventArgs& args)
{
this-udp->ping();
}
void DiarkisUdpBase::OnPing(const DiarkisUdpPingEventArgs& args)
{
// ping is not generated automatically by the library.
// the client has to call `Ping` api on the udp instance.
}