diff --git a/src/oatpp/core/data/buffer/FIFOBuffer.cpp b/src/oatpp/core/data/buffer/FIFOBuffer.cpp index 50c3a0ab..22446708 100644 --- a/src/oatpp/core/data/buffer/FIFOBuffer.cpp +++ b/src/oatpp/core/data/buffer/FIFOBuffer.cpp @@ -288,13 +288,13 @@ data::v_io_size FIFOBuffer::flushToStream(data::stream::OutputStream& stream) { oatpp::async::Action FIFOBuffer::flushToStreamAsync(oatpp::async::AbstractCoroutine* parentCoroutine, const oatpp::async::Action& actionOnFinish, - data::stream::OutputStream& stream) + const std::shared_ptr& stream) { class FlushCoroutine : public oatpp::async::Coroutine { private: - FIFOBuffer* m_fifo; - data::stream::OutputStream* m_stream; + std::shared_ptr m_fifo; + std::shared_ptr m_stream; private: const void* m_data1; @@ -304,7 +304,7 @@ oatpp::async::Action FIFOBuffer::flushToStreamAsync(oatpp::async::AbstractCorout data::v_io_size m_size2; public: - FlushCoroutine(FIFOBuffer* fifo, data::stream::OutputStream* stream) + FlushCoroutine(const std::shared_ptr& fifo, const std::shared_ptr& stream) : m_fifo(fifo) , m_stream(stream) {} @@ -336,15 +336,15 @@ oatpp::async::Action FIFOBuffer::flushToStreamAsync(oatpp::async::AbstractCorout } Action fullFlush() { - return data::stream::writeExactSizeDataAsyncInline(m_stream, m_data1, m_size1, yieldTo(&FlushCoroutine::beforeFinish)); + return data::stream::writeExactSizeDataAsyncInline(m_stream.get(), m_data1, m_size1, yieldTo(&FlushCoroutine::beforeFinish)); } Action partialFlush1() { - return data::stream::writeExactSizeDataAsyncInline(m_stream, m_data1, m_size1, yieldTo(&FlushCoroutine::partialFlush2)); + return data::stream::writeExactSizeDataAsyncInline(m_stream.get(), m_data1, m_size1, yieldTo(&FlushCoroutine::partialFlush2)); } Action partialFlush2() { - return data::stream::writeExactSizeDataAsyncInline(m_stream, m_data2, m_size2, yieldTo(&FlushCoroutine::beforeFinish)); + return data::stream::writeExactSizeDataAsyncInline(m_stream.get(), m_data2, m_size2, yieldTo(&FlushCoroutine::beforeFinish)); } Action beforeFinish() { @@ -354,7 +354,7 @@ oatpp::async::Action FIFOBuffer::flushToStreamAsync(oatpp::async::AbstractCorout }; - return parentCoroutine->startCoroutine(actionOnFinish, this, &stream); + return parentCoroutine->startCoroutine(actionOnFinish, shared_from_this(), stream); } diff --git a/src/oatpp/core/data/buffer/FIFOBuffer.hpp b/src/oatpp/core/data/buffer/FIFOBuffer.hpp index b970be0d..a1f4c641 100644 --- a/src/oatpp/core/data/buffer/FIFOBuffer.hpp +++ b/src/oatpp/core/data/buffer/FIFOBuffer.hpp @@ -36,7 +36,7 @@ namespace oatpp { namespace data { namespace buffer { * FIFO operations over the buffer * !FIFOBuffer is NOT an IOStream despite having similar APIs! */ -class FIFOBuffer { +class FIFOBuffer : public std::enable_shared_from_this { private: p_char8 m_buffer; v_io_size m_bufferSize; @@ -132,7 +132,7 @@ public: */ oatpp::async::Action flushToStreamAsync(oatpp::async::AbstractCoroutine* parentCoroutine, const oatpp::async::Action& actionOnFinish, - data::stream::OutputStream& stream); + const std::shared_ptr& stream); }; diff --git a/src/oatpp/core/data/stream/StreamBufferedProxy.cpp b/src/oatpp/core/data/stream/StreamBufferedProxy.cpp index e5283dda..501d837b 100644 --- a/src/oatpp/core/data/stream/StreamBufferedProxy.cpp +++ b/src/oatpp/core/data/stream/StreamBufferedProxy.cpp @@ -27,24 +27,24 @@ namespace oatpp { namespace data{ namespace stream { data::v_io_size OutputStreamBufferedProxy::write(const void *data, data::v_io_size count) { - if(m_buffer.availableToWrite() > 0) { - return m_buffer.write(data, count); + if(m_buffer->availableToWrite() > 0) { + return m_buffer->write(data, count); } else { - auto bytesFlushed = m_buffer.readAndWriteToStream(*m_outputStream, m_buffer.getBufferSize()); + auto bytesFlushed = m_buffer->readAndWriteToStream(*m_outputStream, m_buffer->getBufferSize()); if(bytesFlushed > 0) { - return m_buffer.write(data, count); + return m_buffer->write(data, count); } return bytesFlushed; } } data::v_io_size OutputStreamBufferedProxy::flush() { - return m_buffer.flushToStream(*m_outputStream); + return m_buffer->flushToStream(*m_outputStream); } oatpp::async::Action OutputStreamBufferedProxy::flushAsync(oatpp::async::AbstractCoroutine* parentCoroutine, - const oatpp::async::Action& actionOnFinish) { - return m_buffer.flushToStreamAsync(parentCoroutine, actionOnFinish, *m_outputStream); + const oatpp::async::Action& actionOnFinish) { + return m_buffer->flushToStreamAsync(parentCoroutine, actionOnFinish, m_outputStream); } data::v_io_size InputStreamBufferedProxy::read(void *data, data::v_io_size count) { diff --git a/src/oatpp/core/data/stream/StreamBufferedProxy.hpp b/src/oatpp/core/data/stream/StreamBufferedProxy.hpp index 80a7861c..85f96f8b 100644 --- a/src/oatpp/core/data/stream/StreamBufferedProxy.hpp +++ b/src/oatpp/core/data/stream/StreamBufferedProxy.hpp @@ -41,7 +41,7 @@ public: private: std::shared_ptr m_outputStream; std::shared_ptr m_bufferPtr; - buffer::FIFOBuffer m_buffer; + std::shared_ptr m_buffer; public: OutputStreamBufferedProxy(const std::shared_ptr& outputStream, const std::shared_ptr& bufferPtr, @@ -49,12 +49,12 @@ public: v_bufferSize bufferSize) : m_outputStream(outputStream) , m_bufferPtr(bufferPtr) - , m_buffer(buffer, bufferSize) + , m_buffer(std::make_shared(buffer, bufferSize)) {} public: static std::shared_ptr createShared(const std::shared_ptr& outputStream, - const std::shared_ptr& buffer) + const std::shared_ptr& buffer) { return Shared_OutputStreamBufferedProxy_Pool::allocateShared(outputStream, buffer, @@ -78,7 +78,7 @@ public: const oatpp::async::Action& actionOnFinish); void setBufferPosition(data::v_io_size readPosition, data::v_io_size writePosition, bool canRead) { - m_buffer.setBufferPosition(readPosition, writePosition, canRead); + m_buffer->setBufferPosition(readPosition, writePosition, canRead); } };