SSLStream (WIP)
This commit is contained in:
@@ -183,14 +183,25 @@ StreamError translateWinError() noexcept
|
||||
StreamError TCPStream::readRaw(std::span<std::uint8_t> buffer, const ReadOptions& options, std::size_t* outBytesRead)
|
||||
{
|
||||
MIJIN_ASSERT(isOpen(), "Socket is not open.");
|
||||
setAsync(false);
|
||||
setNoblock(options.noBlock);
|
||||
|
||||
const long bytesRead = osRecv(handle_, buffer, readFlags(options));
|
||||
if (bytesRead < 0)
|
||||
{
|
||||
return translateErrno();
|
||||
if (!options.noBlock || errno != EAGAIN)
|
||||
{
|
||||
return translateErrno();
|
||||
}
|
||||
if (outBytesRead != nullptr)
|
||||
{
|
||||
*outBytesRead = 0;
|
||||
}
|
||||
return StreamError::SUCCESS;
|
||||
}
|
||||
if (outBytesRead != nullptr)
|
||||
{
|
||||
*outBytesRead = static_cast<std::size_t>(bytesRead);
|
||||
}
|
||||
*outBytesRead = static_cast<std::size_t>(bytesRead);
|
||||
|
||||
return StreamError::SUCCESS;
|
||||
}
|
||||
@@ -198,7 +209,7 @@ StreamError TCPStream::readRaw(std::span<std::uint8_t> buffer, const ReadOptions
|
||||
StreamError TCPStream::writeRaw(std::span<const std::uint8_t> buffer)
|
||||
{
|
||||
MIJIN_ASSERT(isOpen(), "Socket is not open.");
|
||||
setAsync(false);
|
||||
setNoblock(false);
|
||||
|
||||
if (osSend(handle_, buffer, 0) < 0)
|
||||
{
|
||||
@@ -211,7 +222,7 @@ StreamError TCPStream::writeRaw(std::span<const std::uint8_t> buffer)
|
||||
mijin::Task<StreamError> TCPStream::c_readRaw(std::span<std::uint8_t> buffer, const ReadOptions& options, std::size_t* outBytesRead)
|
||||
{
|
||||
MIJIN_ASSERT(isOpen(), "Socket is not open.");
|
||||
setAsync(true);
|
||||
setNoblock(true);
|
||||
|
||||
if (buffer.empty())
|
||||
{
|
||||
@@ -249,7 +260,7 @@ Task<StreamError> TCPStream::c_writeRaw(std::span<const std::uint8_t> buffer)
|
||||
co_return StreamError::SUCCESS;
|
||||
}
|
||||
|
||||
setAsync(true);
|
||||
setNoblock(true);
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -270,7 +281,7 @@ Task<StreamError> TCPStream::c_writeRaw(std::span<const std::uint8_t> buffer)
|
||||
}
|
||||
}
|
||||
|
||||
void TCPStream::setAsync(bool async)
|
||||
void TCPStream::setNoblock(bool async)
|
||||
{
|
||||
if (async == async_)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user