2022-08-28 19:02:06 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
2022-12-12 23:50:05 +00:00
|
|
|
File: AuProtocolStack.hpp
|
2022-08-28 19:02:06 +00:00
|
|
|
Date: 2022-8-24
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2023-04-25 11:13:16 +00:00
|
|
|
#include "../AuIOPipeProcessor.hpp"
|
2023-09-21 07:02:02 +00:00
|
|
|
#include "AuProtocolStackSpecialReader.hpp"
|
2023-09-21 20:18:59 +00:00
|
|
|
#include "AuProtocolStackSpecialWriter.hpp"
|
2023-04-25 11:13:16 +00:00
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
namespace Aurora::IO::Protocol
|
|
|
|
{
|
|
|
|
struct ProtocolPiece;
|
|
|
|
|
2023-04-28 01:41:45 +00:00
|
|
|
struct ProtocolStack : IProtocolStack,
|
|
|
|
AuEnableSharedFromThis<ProtocolStack>
|
2022-08-28 19:02:06 +00:00
|
|
|
{
|
2023-09-21 07:02:02 +00:00
|
|
|
ProtocolStack();
|
2022-08-28 19:02:06 +00:00
|
|
|
~ProtocolStack();
|
|
|
|
|
2023-06-04 18:02:33 +00:00
|
|
|
void Terminate();
|
2023-04-25 11:13:16 +00:00
|
|
|
bool DoTick() override;
|
2022-08-28 19:02:06 +00:00
|
|
|
bool DoTick(const AuSPtr<AuByteBuffer> &read, const AuSPtr<ProtocolPiece> &pPiece);
|
|
|
|
|
2023-09-21 07:02:02 +00:00
|
|
|
bool DoTickEx(bool bPermitRead = true);
|
|
|
|
|
|
|
|
bool TryReadMore(bool bForce = false);
|
|
|
|
|
2023-11-30 09:39:56 +00:00
|
|
|
AuSPtr<IProtocolPiece> AddInterceptor(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize) override;
|
|
|
|
AuSPtr<IProtocolPiece> AddInterceptorEx(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize) override;
|
|
|
|
AuSPtr<IProtocolPiece> AddSingleFrameProcessor(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx) override;
|
|
|
|
AuSPtr<IProtocolPiece> AddSingleFrameProcessorEx(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize) override;
|
|
|
|
AuSPtr<IProtocolPiece> AddInterceptorDynamicBuffer(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax) override;
|
|
|
|
AuSPtr<IProtocolPiece> AddSingleFrameProcessorDynamicBuffer(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptorEx, AuUInt uOutputBufferSize, AuUInt uOutputBufferSizeMax) override;
|
2023-10-07 19:08:46 +00:00
|
|
|
|
2022-09-29 10:45:08 +00:00
|
|
|
AuSPtr<IProtocolPiece> AddEndInterceptor(const AuSPtr<IProtocolInterceptorEx> &pInterceptor) override;
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
void Destroy() override;
|
|
|
|
|
2023-11-30 09:39:56 +00:00
|
|
|
AuSPtr<IProtocolPiece> AddInterceptorWhere(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptor> &pInterceptor, AuUInt uOutputBufferSize);
|
|
|
|
AuSPtr<IProtocolPiece> AddInterceptorWhereEx(EProtocolWhere eWhere, const AuSPtr<IProtocolInterceptorEx> &pInterceptor, AuUInt uOutputBufferSize, bool bMultipleTick, AuOptional<AuUInt> uMax = {});
|
2022-09-04 00:16:49 +00:00
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
AuSPtr<IStreamWriter> AsStreamWriter() override;
|
|
|
|
AuSPtr<Memory::ByteBuffer> AsWritableByteBuffer() override;
|
|
|
|
|
|
|
|
AuSPtr<IStreamReader> AsStreamReader() override;
|
|
|
|
AuSPtr<Memory::ByteBuffer> AsReadableByteBuffer() override;
|
|
|
|
|
2023-04-28 01:41:45 +00:00
|
|
|
AuList<AuSPtr<IProtocolPiece>> GetArrayOfInterceptors() override;
|
|
|
|
AuSPtr<IProtocolPiece> GetInterceptorAtIndex(AuUInt32 uIndex) override;
|
|
|
|
|
2023-10-07 19:08:46 +00:00
|
|
|
bool IsValid() override;
|
|
|
|
|
2023-09-21 07:02:02 +00:00
|
|
|
EProtocolStackCreateType eType;
|
|
|
|
bool bDead {};
|
|
|
|
|
|
|
|
bool bStreamReaderFlagAdhocRead {};
|
|
|
|
bool bStreamReaderFlagAdhocPump {};
|
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
AuSPtr<AuByteBuffer> pSourceBufer;
|
|
|
|
bool bOwnsSource {};
|
|
|
|
|
|
|
|
AuSPtr<AuByteBuffer> pDrainBuffer;
|
|
|
|
|
|
|
|
AuSPtr<ProtocolPiece> pBottomPiece;
|
|
|
|
AuSPtr<ProtocolPiece> pTopPiece;
|
2022-09-02 19:53:25 +00:00
|
|
|
|
|
|
|
bool bWrittenEnd {};
|
2023-04-25 11:13:16 +00:00
|
|
|
|
|
|
|
AuWPtr<AuIO::IOPipeWork> pPipeWork;
|
2023-04-25 11:57:02 +00:00
|
|
|
bool bKillPipeOnFirstRootLevelFalse {};
|
2023-04-26 06:37:14 +00:00
|
|
|
|
|
|
|
AuSPtr<IStreamReader> pStreamReaderCache;
|
|
|
|
AuSPtr<IStreamWriter> pStreamWriterCache;
|
2023-06-11 14:09:07 +00:00
|
|
|
|
2023-09-21 07:02:02 +00:00
|
|
|
AuSPtr<IStreamReader> pStreamReaderAsInputSource;
|
|
|
|
AuUInt uPreferredFragmentSize {};
|
|
|
|
|
|
|
|
SpecialReader readView;
|
2023-09-21 20:18:59 +00:00
|
|
|
SpecialWriter writeView;
|
|
|
|
|
|
|
|
AuRenterableMutex mutex;
|
2023-09-21 07:02:02 +00:00
|
|
|
|
2023-06-11 14:09:07 +00:00
|
|
|
void DiscardAllocCaches();
|
2022-08-28 19:02:06 +00:00
|
|
|
};
|
|
|
|
}
|