[+] why not?

This commit is contained in:
Reece Wilson 2023-06-04 21:18:44 +01:00
parent 78091bf84b
commit 8b36562cf0
3 changed files with 91 additions and 18 deletions

View File

@ -119,14 +119,69 @@ namespace Aurora::IO::Net
AuSPtr<IStreamWriter> SocketChannel::AsStreamWriter()
{
if (this->pSendProtocol)
{
return this->pSendProtocol->AsStreamWriter();
}
else if (this->pCachedWriter)
if (this->pCachedWriter)
{
return this->pCachedWriter;
}
else if (this->pSendProtocol)
{
struct C : IO::IStreamWriter
{
AuWPtr<IO::IStreamWriter> swpIStreamWriter;
AuWPtr<SocketChannel> swpChannel;
C(AuWPtr<SocketChannel> swpChannel,
AuWPtr<IStreamWriter> swpIStreamWriter) :
swpIStreamWriter(swpIStreamWriter),
swpChannel(swpChannel)
{
}
virtual EStreamError IsOpen() override
{
if (auto pChannel = AuTryLockMemoryType(this->swpIStreamWriter))
{
return EStreamError::eErrorNone;
}
else
{
return EStreamError::eErrorHandleClosed;
}
}
virtual EStreamError Write(const AuMemoryViewStreamRead &read) override
{
if (auto pChannel = AuTryLockMemoryType(this->swpIStreamWriter))
{
return pChannel->Write(read);
}
else
{
return EStreamError::eErrorHandleClosed;
}
}
virtual void Close() override
{
if (auto pChannel = AuTryLockMemoryType(this->swpChannel))
{
pChannel->pParent_->Shutdown(false);
}
}
virtual void Flush() override
{
if (auto pChannel = AuTryLockMemoryType(this->swpChannel))
{
pChannel->pParent_->ToChannel()->ScheduleOutOfFrameWrite();
}
}
};
return this->pCachedWriter = AuMakeSharedThrow<C>(AuSPtr<SocketChannel>(this->pParent_->SharedFromThis(), this),
this->pSendProtocol->AsStreamWriter());
}
else
{
struct A : IO::Buffered::BlobWriter

View File

@ -108,8 +108,8 @@ namespace Aurora::IO::Net
AuSPtr<Protocol::IProtocolStack> pRecvProtocol;
AuSPtr<Protocol::IProtocolStack> pSendProtocol;
AuSPtr<IO::Buffered::BlobReader> pCachedReader;
AuSPtr<IO::Buffered::BlobWriter> pCachedWriter;
AuSPtr<IO::IStreamReader> pCachedReader;
AuSPtr<IO::IStreamWriter> pCachedWriter;
AuThreadPrimitives::SpinLock spinLock;
AuList<AuSPtr<ISocketChannelEventListener>> eventListeners;

View File

@ -120,10 +120,14 @@ namespace Aurora::IO::Protocol
}
};
void Flush() override
virtual void Flush() override
{
};
if (auto pStack = AuTryLockMemoryType(this->pStack))
{
pStack->DoTick();
}
}
virtual AuSPtr<Memory::ByteBuffer> GetOutputBuffer() override
{
@ -239,12 +243,15 @@ namespace Aurora::IO::Protocol
{
pStack->Terminate();
}
};
}
void Flush() override
virtual void Flush() override
{
};
if (auto pStack = AuTryLockMemoryType(this->pStack))
{
pStack->DoTick();
}
}
virtual AuSPtr<Memory::ByteBuffer> GetOutputBuffer() override
{
@ -343,12 +350,15 @@ namespace Aurora::IO::Protocol
{
pStack->Terminate();
}
};
}
void Flush() override
virtual void Flush() override
{
};
if (auto pStack = AuTryLockMemoryType(this->pStack))
{
pStack->DoTick();
}
}
virtual AuSPtr<Memory::ByteBuffer> GetOutputBuffer() override
{
@ -451,6 +461,14 @@ namespace Aurora::IO::Protocol
pStack->Terminate();
}
}
virtual void Flush() override
{
if (auto pStack = AuTryLockMemoryType(wpStack))
{
pStack->DoTick();
}
}
};
return this->pStreamWriterCache = AuMakeShared<A>(this->pSourceBufer, this->SharedFromThis());