AuroraRuntime/Source/IO/TLS/TLSProtocolSend.cpp
Reece 1fa433540b [*] Experimental lower-latency IO pipes
[*] revert win32 net tx hardening - do not use the Reset function to null pSocket
[*] fix a bytebuffer circular buffer path
[*] update how TLS protocol stacks can snap the stack
2023-05-11 16:05:00 +01:00

65 lines
1.7 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: TLSProtocolSend.cpp
Date: 2022-8-24
Author: Reece
***/
#include "TLS.hpp"
#include "TLSContext.hpp"
namespace Aurora::IO::TLS
{
TLSProtocolSend::TLSProtocolSend(TLSContext *pParent) :
pParent_(pParent)
{
}
bool TLSProtocolSend::OnDataAvailable(const AuSPtr<Memory::ByteBuffer> &pReadInByteBuffer,
const AuSPtr<Memory::ByteBuffer> &pWriteOutByteBuffer)
{
if (!this->pParent_->bIsAlive)
{
return true;
}
if (pReadInByteBuffer->writePtr == pReadInByteBuffer->readPtr)
{
return true;
}
while (pReadInByteBuffer->writePtr != pReadInByteBuffer->readPtr)
{
auto pDest = pReadInByteBuffer->GetNextLinearRead();
const AuUInt8 *pBase { pDest.ToPointer() };
AuUInt uCount { pDest.length };
if (!uCount)
{
return true;
}
int iRet = ::mbedtls_ssl_write(&this->pParent_->ssl,
pBase,
uCount);
if ((iRet == MBEDTLS_ERR_SSL_WANT_READ) ||
(iRet == MBEDTLS_ERR_SSL_WANT_WRITE))
{
return true;
}
if (iRet < 0)
{
this->pParent_->iFatalError = iRet;
SysPushErrorNet("{}", iRet);
this->pParent_->OnFatal();
return false;
}
pReadInByteBuffer->readPtr += iRet;
}
return true;
}
}