AuroraRuntime/Source/IO/Net/AuNetSocketChannel.hpp
2023-06-04 21:18:44 +01:00

124 lines
4.1 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"
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 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;
SocketStats & GetSendStatsEx();
SocketStats & GetRecvStatsEx();
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 Release();
private:
SocketBase * pParent_;
SocketStats sendStats_;
SocketStats recvStats_;
};
}