[+] ISocketServer::GetServerRecvStats()

[+] ISocketServer::GetServerSendStats()
This commit is contained in:
Reece Wilson 2023-12-01 14:49:30 +00:00
parent 81871ed0b8
commit e0f74d6160
13 changed files with 131 additions and 3 deletions

View File

@ -15,5 +15,7 @@ namespace Aurora::IO::Net
virtual AuUInt32 GetSessionCount() = 0; virtual AuUInt32 GetSessionCount() = 0;
virtual AuSPtr<ISocketServerLimits> GetLimits() = 0; virtual AuSPtr<ISocketServerLimits> GetLimits() = 0;
virtual AuSPtr<ISocketServerDriver> GetServerDriver() = 0; virtual AuSPtr<ISocketServerDriver> GetServerDriver() = 0;
virtual AuSPtr<ISocketStats> GetServerRecvStats() = 0;
virtual AuSPtr<ISocketStats> GetServerSendStats() = 0;
}; };
} }

View File

@ -493,6 +493,11 @@ namespace Aurora::IO::Net
auto uHeadDelta = pReadableBuffer ? (pReadableBuffer->readPtr - pStartOffset) : 0; auto uHeadDelta = pReadableBuffer ? (pReadableBuffer->readPtr - pStartOffset) : 0;
this->socketChannel_.GetRecvStatsEx().AddBytes(uHeadDelta); this->socketChannel_.GetRecvStatsEx().AddBytes(uHeadDelta);
if (auto pServerRecvStats = this->socketChannel_.GetRecvStatsEx2())
{
pServerRecvStats->AddBytes(uHeadDelta);
}
} }
const NetError &SocketBase::GetError() const NetError &SocketBase::GetError()

View File

@ -132,6 +132,7 @@ namespace Aurora::IO::Net
friend struct NetWriteQueue; friend struct NetWriteQueue;
friend struct SocketChannelOutput; friend struct SocketChannelOutput;
friend struct SocketChannel;
NetEndpoint remoteEndpoint_; NetEndpoint remoteEndpoint_;
NetEndpoint localEndpoint_; NetEndpoint localEndpoint_;

View File

@ -17,6 +17,7 @@
#include "AuNetWorker.hpp" #include "AuNetWorker.hpp"
#include <Source/IO/Protocol/Protocol.hpp> #include <Source/IO/Protocol/Protocol.hpp>
#include <Source/IO/Protocol/AuProtocolStack.hpp> #include <Source/IO/Protocol/AuProtocolStack.hpp>
#include "AuNetSocketServer.hpp"
namespace Aurora::IO::Net namespace Aurora::IO::Net
{ {
@ -313,6 +314,44 @@ namespace Aurora::IO::Net
return this->recvStats_; return this->recvStats_;
} }
SocketStats *SocketChannel::GetSendStatsEx2()
{
if (auto pTest = this->pParent_->GetSocketServer())
{
if (auto pWP2 = this->pParent_->wpParent2_)
{
return &pWP2->sendStats_;
}
else
{
return {};
}
}
else
{
return {};
}
}
SocketStats *SocketChannel::GetRecvStatsEx2()
{
if (auto pTest = this->pParent_->GetSocketServer())
{
if (auto pWP2 = this->pParent_->wpParent2_)
{
return &pWP2->recvStats_;
}
else
{
return {};
}
}
else
{
return {};
}
}
void SocketChannel::AddEventListener(const AuSPtr<ISocketChannelEventListener> &pListener) void SocketChannel::AddEventListener(const AuSPtr<ISocketChannelEventListener> &pListener)
{ {
AU_LOCK_GUARD(this->spinLock); AU_LOCK_GUARD(this->spinLock);

View File

@ -84,8 +84,10 @@ namespace Aurora::IO::Net
AuSPtr<ISocketChannelLimits> GetChannelLimits() override; AuSPtr<ISocketChannelLimits> GetChannelLimits() override;
SocketStats & GetSendStatsEx(); SocketStats &GetSendStatsEx();
SocketStats & GetRecvStatsEx(); SocketStats &GetRecvStatsEx();
SocketStats *GetSendStatsEx2();
SocketStats *GetRecvStatsEx2();
void Establish(); void Establish();

View File

@ -281,6 +281,11 @@ namespace Aurora::IO::Net
AuStaticCast<SocketChannel>(this->pParent_->ToChannel())->GetSendStatsEx().AddBytes(length); AuStaticCast<SocketChannel>(this->pParent_->ToChannel())->GetSendStatsEx().AddBytes(length);
if (auto pServerSendStats = AuStaticCast<SocketChannel>(this->pParent_->ToChannel())->GetSendStatsEx2())
{
pServerSendStats->AddBytes(length);
}
if (!length) if (!length)
{ {
this->pParent_->SendErrorBeginShutdown({}); this->pParent_->SendErrorBeginShutdown({});

View File

@ -130,6 +130,16 @@ namespace Aurora::IO::Net
return this->pFactory_; return this->pFactory_;
} }
AuSPtr<ISocketStats> SocketServer::GetServerRecvStats()
{
return AuSPtr<ISocketStats>(this->SharedFromThis(), &this->recvStats_);
}
AuSPtr<ISocketStats> SocketServer::GetServerSendStats()
{
return AuSPtr<ISocketStats>(this->SharedFromThis(), &this->sendStats_);
}
AuSPtr<ISocketServerLimits> SocketServer::GetLimits() AuSPtr<ISocketServerLimits> SocketServer::GetLimits()
{ {
return AuSPtr<ISocketServerLimits>(this->SharedFromThis(), &this->serverLimits_); return AuSPtr<ISocketServerLimits>(this->SharedFromThis(), &this->serverLimits_);

View File

@ -39,6 +39,8 @@ namespace Aurora::IO::Net
AuSPtr<ISocketServerLimits> GetLimits() override; AuSPtr<ISocketServerLimits> GetLimits() override;
AuList<AuSPtr<ISocket>> GetChildren() override; AuList<AuSPtr<ISocket>> GetChildren() override;
AuUInt32 GetSessionCount() override; AuUInt32 GetSessionCount() override;
AuSPtr<ISocketStats> GetServerRecvStats() override;
AuSPtr<ISocketStats> GetServerSendStats() override;
virtual void FinishConstructAsync() override; virtual void FinishConstructAsync() override;
@ -92,7 +94,10 @@ namespace Aurora::IO::Net
private: private:
friend struct SocketBase; friend struct SocketBase;
friend struct SocketChannel;
SocketStats sendStats_;
SocketStats recvStats_;
AuSPtr<ISocketServerDriver> pDriver_; AuSPtr<ISocketServerDriver> pDriver_;
AuUInt32 uMaxConnections_; AuUInt32 uMaxConnections_;
AuSPtr<ISocketDriverFactory> pFactory_; AuSPtr<ISocketDriverFactory> pFactory_;

View File

@ -89,7 +89,6 @@ namespace Aurora::IO::Net
} }
} }
AuUInt32 NetDatagramEmulatorISocketServer::GetSessionCount() AuUInt32 NetDatagramEmulatorISocketServer::GetSessionCount()
{ {
if (auto pParent = this->pParent) if (auto pParent = this->pParent)
@ -101,4 +100,28 @@ namespace Aurora::IO::Net
return {}; return {};
} }
} }
AuSPtr<ISocketStats> NetDatagramEmulatorISocketServer::GetServerRecvStats()
{
if (auto pParent = this->pParent)
{
return AuSPtr<ISocketStats> { pParent->SharedFromThis(), pParent->GetRecvStats() };
}
else
{
return {};
}
}
AuSPtr<ISocketStats> NetDatagramEmulatorISocketServer::GetServerSendStats()
{
if (auto pParent = this->pParent)
{
return AuSPtr<ISocketStats> { pParent->SharedFromThis(), pParent->GetSendStats() };
}
else
{
return {};
}
}
} }

View File

@ -32,5 +32,7 @@ namespace Aurora::IO::Net
AuList<AuSPtr<ISocket>> GetChildren() override; AuList<AuSPtr<ISocket>> GetChildren() override;
AuSPtr<INetWorker> GetLockedWorkerThread() override; AuSPtr<INetWorker> GetLockedWorkerThread() override;
AuUInt32 GetSessionCount() override; AuUInt32 GetSessionCount() override;
AuSPtr<ISocketStats> GetServerRecvStats() override;
AuSPtr<ISocketStats> GetServerSendStats() override;
}; };
} }

View File

@ -394,4 +394,14 @@ namespace Aurora::IO::Net
{ {
return this->pSocketDriverFactory_; return this->pSocketDriverFactory_;
} }
SocketStats *NetDatagramSocketServer::GetSendStats()
{
return &this->sendStats_;
}
SocketStats *NetDatagramSocketServer::GetRecvStats()
{
return &this->recvStats_;
}
} }

View File

@ -10,6 +10,7 @@
#include "AuNetDatagramSocketServerDriver.hpp" #include "AuNetDatagramSocketServerDriver.hpp"
#include "AuNetDatagramEmulatorISocketServer.hpp" #include "AuNetDatagramEmulatorISocketServer.hpp"
#include "AuNetDatagramSocketEviction.hpp" #include "AuNetDatagramSocketEviction.hpp"
#include "../AuSocketStats.hpp"
namespace Aurora::IO::Net namespace Aurora::IO::Net
{ {
@ -60,6 +61,9 @@ namespace Aurora::IO::Net
AuSPtr<ISocketDriverFactory> GetFactoryDriver(); AuSPtr<ISocketDriverFactory> GetFactoryDriver();
AuSPtr<IDatagramServer> ToServer(); AuSPtr<IDatagramServer> ToServer();
SocketStats *GetSendStats();
SocketStats *GetRecvStats();
void DispatchNew(AuSPtr<NetDatagramSocketServerSession> pSession); void DispatchNew(AuSPtr<NetDatagramSocketServerSession> pSession);
const AuUInt32 uSocketTimeoutAnyMS; const AuUInt32 uSocketTimeoutAnyMS;
@ -85,5 +89,7 @@ namespace Aurora::IO::Net
AuSPtr<ISocketDriverFactory> pSocketDriverFactory_; AuSPtr<ISocketDriverFactory> pSocketDriverFactory_;
NetDatagramSocketEviction eviction; NetDatagramSocketEviction eviction;
AuThreadPrimitives::Mutex mutex_; AuThreadPrimitives::Mutex mutex_;
SocketStats sendStats_;
SocketStats recvStats_;
}; };
} }

View File

@ -15,6 +15,7 @@
#endif #endif
#include "../AuNetDatagramServer.hpp" #include "../AuNetDatagramServer.hpp"
#include "AuNetDatagramSocketServer.hpp"
static const auto kDefaultBufferSize = 64 * 1024; static const auto kDefaultBufferSize = 64 * 1024;
@ -160,6 +161,15 @@ namespace Aurora::IO::Net
pMem->ptr = this->outputBuffer.readPtr; pMem->ptr = this->outputBuffer.readPtr;
pMem->length = uDelta; pMem->length = uDelta;
this->sendStats_.AddBytes(uDelta);
if (auto pParent = AuTryLockMemoryType(this->pParent_->pParentServer))
{
if (auto pSendStats = pParent->GetSendStats())
{
pSendStats->AddBytes(uDelta);
}
}
this->outputBuffer.readPtr += uDelta; this->outputBuffer.readPtr += uDelta;
pWriteTransaction->SetCallback(AuMakeSharedThrow<AuIO::IAsyncFinishedSubscriberFunctional>([=](AuUInt64 uOffset, AuUInt32 uLength) pWriteTransaction->SetCallback(AuMakeSharedThrow<AuIO::IAsyncFinishedSubscriberFunctional>([=](AuUInt64 uOffset, AuUInt32 uLength)
@ -450,6 +460,14 @@ namespace Aurora::IO::Net
{ {
this->recvStats_.AddBytes(pBuffer->RemainingBytes()); this->recvStats_.AddBytes(pBuffer->RemainingBytes());
if (auto pParent = AuTryLockMemoryType(this->pParent_->pParentServer))
{
if (auto pRecvStats = pParent->GetRecvStats())
{
pRecvStats->AddBytes(pBuffer->RemainingBytes());
}
}
if (this->pBuffer) if (this->pBuffer)
{ {
if (!this->bOwnsBuffer) if (!this->bOwnsBuffer)