Better stream processing methods

This commit is contained in:
lganzzzo 2019-02-07 07:42:52 +02:00
parent fe4b6fd4b1
commit 10d961b99b
4 changed files with 10 additions and 38 deletions

View File

@ -241,28 +241,6 @@ oatpp::async::Action transferAsync(oatpp::async::AbstractCoroutine* parentCorout
}
oatpp::async::Action writeSomeDataAsyncInline(oatpp::data::stream::OutputStream* stream,
const void*& data,
data::v_io_size& size,
const oatpp::async::Action& nextAction) {
auto res = stream->write(data, size);
if(res == data::IOError::WAIT_RETRY) {
return oatpp::async::Action::_WAIT_RETRY;
} else if(res == data::IOError::RETRY) {
return oatpp::async::Action::_REPEAT;
} else if(res == data::IOError::BROKEN_PIPE) {
return oatpp::async::Action::_ABORT;
} else if(res < 0) {
return oatpp::async::Action(oatpp::async::Error(Errors::ERROR_ASYNC_FAILED_TO_WRITE_DATA));
}
data = &((p_char8) data)[res];
size = size - res;
if(res < size && res > 0) {
return oatpp::async::Action::_REPEAT;
}
return nextAction;
}
oatpp::async::Action writeExactSizeDataAsyncInline(oatpp::data::stream::OutputStream* stream,
const void*& data,
data::v_io_size& size,
@ -280,10 +258,11 @@ oatpp::async::Action writeExactSizeDataAsyncInline(oatpp::data::stream::OutputSt
return oatpp::async::Action(oatpp::async::Error(Errors::ERROR_ASYNC_FAILED_TO_WRITE_DATA));
}
data = &((p_char8) data)[res];
size = size - res;
if(res < size) {
size = size - res;
return oatpp::async::Action::_REPEAT;
}
size = size - res;
return nextAction;
}
@ -322,10 +301,11 @@ oatpp::async::Action readExactSizeDataAsyncInline(oatpp::data::stream::InputStre
return oatpp::async::Action(oatpp::async::Error(Errors::ERROR_ASYNC_FAILED_TO_READ_DATA));
}
data = &((p_char8) data)[res];
bytesLeftToRead -= res;
if(res < bytesLeftToRead) {
bytesLeftToRead -= res;
return oatpp::async::Action::_REPEAT;
}
bytesLeftToRead -= res;
return nextAction;
}

View File

@ -155,15 +155,7 @@ oatpp::async::Action transferAsync(oatpp::async::AbstractCoroutine* parentCorout
const std::shared_ptr<OutputStream>& toStream,
oatpp::data::v_io_size transferSize,
const std::shared_ptr<oatpp::data::buffer::IOBuffer>& buffer);
/**
* Async write data withot starting new Coroutine.
* Should be called from a separate Coroutine method
*/
oatpp::async::Action writeSomeDataAsyncInline(oatpp::data::stream::OutputStream* stream,
const void*& data,
data::v_io_size& size,
const oatpp::async::Action& nextAction);
oatpp::async::Action writeExactSizeDataAsyncInline(oatpp::data::stream::OutputStream* stream,
const void*& data,

View File

@ -46,7 +46,7 @@ public:
};
void runTests() {
/*OATPP_RUN_TEST(oatpp::test::base::RegRuleTest);
OATPP_RUN_TEST(oatpp::test::base::RegRuleTest);
OATPP_RUN_TEST(oatpp::test::base::CommandLineArgumentsTest);
OATPP_RUN_TEST(oatpp::test::memory::MemoryPoolTest);
OATPP_RUN_TEST(oatpp::test::memory::PerfTest);
@ -59,8 +59,8 @@ void runTests() {
OATPP_RUN_TEST(oatpp::test::encoding::UnicodeTest);
OATPP_RUN_TEST(oatpp::test::core::data::share::MemoryLabelTest);
OATPP_RUN_TEST(oatpp::test::network::virtual_::PipeTest);
OATPP_RUN_TEST(oatpp::test::network::virtual_::InterfaceTest);*/
//OATPP_RUN_TEST(oatpp::test::web::FullTest);
OATPP_RUN_TEST(oatpp::test::network::virtual_::InterfaceTest);
OATPP_RUN_TEST(oatpp::test::web::FullTest);
OATPP_RUN_TEST(oatpp::test::web::FullAsyncTest);
}

View File

@ -69,7 +69,7 @@ bool FullAsyncTest::onRun() {
std::thread clientThread([client, server, connectionHandler, objectMapper]{
for(v_int32 i = 0; i < 10; i ++) {
/*
{ // test simple GET
auto response = client->getRoot();
auto value = response->readBodyToString();
@ -98,7 +98,7 @@ bool FullAsyncTest::onRun() {
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_body-Async");
}
*/
{ // test Big Echo with body
oatpp::data::stream::ChunkedBuffer stream;
for(v_int32 i = 0; i < oatpp::data::buffer::IOBuffer::BUFFER_SIZE; i++) {