AuroraRuntime/Source/IO/Net/AuNetSocketChannel.hpp
Jamie Reece Wilson e0f74d6160 [+] ISocketServer::GetServerRecvStats()
[+] ISocketServer::GetServerSendStats()
2023-12-01 14:49:30 +00:00

139 lines
4.4 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuNetSocketChannel.hpp
Date: 2022-8-16
Author: Reece
***/
#pragma once
#include "AuNetWriteQueue.hpp"
#include "AuNetSocketChannelInput.hpp"
#include "AuNetSocketChannelOutput.hpp"
#include "AuSocketStats.hpp"
#include "AuNetChannelLimits.hpp"
namespace Aurora::IO::Net
{
struct SocketBase;
struct NtAsyncNetworkTransaction;
struct SocketChannel : ISocketChannel
{
SocketChannel(SocketBase *pParent);
bool IsValid();
AuSPtr<ISocket> ToParent() override;
void ScheduleOutOfFrameWrite() override;
AuSPtr<IAsyncTransaction> ToReadTransaction() override;
AuSPtr<IAsyncTransaction> ToWriteTransaction() override;
bool SpecifyTCPNoDelay(bool bFuckNagle) override;
bool SpecifyTransactionsHaveIOFence(bool bAllocateFence) override;
bool SpecifyBufferSize(AuUInt uBytes,
const AuSPtr<AuAsync::PromiseCallback<AuNullS, AuNullS>> &pCallbackOptional) override;
bool SpecifyOutputBufferSize(AuUInt uBytes,
const AuSPtr<AuAsync::PromiseCallback<AuNullS, AuNullS>> &pCallbackOptional) override;
bool SpecifyInputBufferSize(AuUInt uBytes,
const AuSPtr<AuAsync::PromiseCallback<AuNullS, AuNullS>> &pCallbackOptional) override;
bool SpecifyManualWrite(bool bEnableDirectAIOWrite) override;
bool SpecifyManualRead(bool bEnableDirectAIORead) override;
bool SpecifyPerTickAsyncReadLimit(AuUInt uBytes) override;
bool GetCurrentTCPNoDelay() override;
AuUInt GetInputBufferSize() override;
AuUInt GetOutputBufferSize() override;
AuSPtr<IStreamReader> AsStreamReader() override;
AuSPtr<Memory::ByteBuffer> AsReadableByteBuffer() override;
AuSPtr<IStreamWriter> AsStreamWriter() override;
AuSPtr<Memory::ByteBuffer> AsWritableByteBuffer() override;
AuSPtr<Protocol::IProtocolStack> NewProtocolRecvStack() override;
AuSPtr<Protocol::IProtocolStack> NewProtocolSendStack() override;
void SetNextFrameTargetLength(AuUInt uNextFrameSize) override;
AuUInt GetNextFrameTargetLength() override;
void SpecifyRecvProtocol(const AuSPtr<Protocol::IProtocolStack> &pRecvProtocol) override;
void SpecifySendProtocol(const AuSPtr<Protocol::IProtocolStack> &pSendProtocol) override;
AuSPtr<ISocketStats> GetRecvStats() override;
AuSPtr<ISocketStats> GetSendStats() override;
void AddEventListener(const AuSPtr<ISocketChannelEventListener> &pListener) override;
void RemoveEventListener(const AuSPtr<ISocketChannelEventListener> &pListener) override;
AuSPtr<ISocketChannelLimits> GetChannelLimits() override;
SocketStats &GetSendStatsEx();
SocketStats &GetRecvStatsEx();
SocketStats *GetSendStatsEx2();
SocketStats *GetRecvStatsEx2();
void Establish();
void DoBufferResizeOnThread(bool bInput,
bool bOutput,
AuUInt uBytes,
const AuSPtr<AuAsync::PromiseCallback<AuNullS, AuNullS>> &pCallbackOptional);
SocketChannelOutput outputChannel;
SocketChannelInput inputChannel;
bool bIsManualRead {};
bool bIsManualWrite {};
bool bIsEstablished {};
bool bTcpNoDelay {};
AuUInt uBytesToFlip { 0 };
AuUInt uBytesInputBuffer { 0 };
AuUInt uBytesOutputBuffer { 0 };
AuUInt uBytesInputBufferRetarget { 0 };
AuSPtr<AuAsync::PromiseCallback<AuNullS, AuNullS>> pRetargetInput;
AuUInt uBytesOutputBufferRetarget { 0 };
AuSPtr<AuAsync::PromiseCallback<AuNullS, AuNullS>> pRetargetOutput;
void DoReallocWriteTick();
void DoReallocReadTick();
AuSPtr<Protocol::IProtocolStack> pRecvProtocol;
AuSPtr<Protocol::IProtocolStack> pSendProtocol;
AuSPtr<IO::IStreamReader> pCachedReader;
AuSPtr<IO::IStreamWriter> pCachedWriter;
AuThreadPrimitives::SpinLock spinLock;
AuList<AuSPtr<ISocketChannelEventListener>> eventListeners;
void StopTime();
void StartTime();
void Release();
private:
SocketBase * pParent_;
SocketStats sendStats_;
SocketStats recvStats_;
NetChannelLimits channelSecurity_;
};
}