Fix to virtual_::Pipe. Crash Fix in StrBuffer (Small_String_Pool)

This commit is contained in:
lganzzzo 2019-02-22 03:10:01 +02:00
parent 1884218e13
commit 6a6133556c
6 changed files with 41 additions and 23 deletions

View File

@ -48,7 +48,7 @@ std::shared_ptr<StrBuffer> StrBuffer::allocShared(const void* data, v_int32 size
if(copyAsOwnData) {
memory::AllocationExtras extras(size + 1);
std::shared_ptr<StrBuffer> ptr;
if(size > getSmStringSize()) {
if(size + 1 > getSmStringSize()) {
ptr = memory::allocateSharedWithExtras<StrBuffer>(extras);
} else {
ptr = memory::customPoolAllocateSharedWithExtras<StrBuffer>(extras, getSmallStringPool());

View File

@ -40,17 +40,21 @@ data::v_io_size Pipe::Reader::read(void *data, data::v_io_size count) {
oatpp::data::v_io_size result;
if(m_nonBlocking) {
if(pipe.m_fifo.availableToRead() > 0) {
result = pipe.m_fifo.read(data, count);
} else if(pipe.m_open) {
result = data::IOError::WAIT_RETRY;
std::unique_lock<std::mutex> lock(pipe.m_mutex, std::try_to_lock);
if(lock.owns_lock()) {
if (pipe.m_fifo.availableToRead() > 0) {
result = pipe.m_fifo.read(data, count);
} else if (pipe.m_open) {
result = data::IOError::WAIT_RETRY;
} else {
result = data::IOError::BROKEN_PIPE;
}
} else {
result = data::IOError::BROKEN_PIPE;
result = data::IOError::WAIT_RETRY;
}
} else {
std::unique_lock<std::mutex> lock(pipe.m_mutex);
while (pipe.m_fifo.availableToRead() == 0 && pipe.m_open) {
pipe.m_conditionWrite.notify_one();
pipe.m_conditionRead.wait(lock);
}
if (pipe.m_fifo.availableToRead() > 0) {
@ -75,22 +79,26 @@ data::v_io_size Pipe::Writer::write(const void *data, data::v_io_size count) {
if(m_maxAvailableToWrtie > -1 && count > m_maxAvailableToWrtie) {
count = m_maxAvailableToWrtie;
}
Pipe& pipe = *m_pipe;
oatpp::data::v_io_size result;
if(m_nonBlocking) {
if(pipe.m_fifo.availableToWrite() > 0) {
result = pipe.m_fifo.write(data, count);
} else if(pipe.m_open) {
result = data::IOError::WAIT_RETRY;
std::unique_lock<std::mutex> lock(pipe.m_mutex, std::try_to_lock);
if(lock.owns_lock()) {
if (pipe.m_fifo.availableToWrite() > 0) {
result = pipe.m_fifo.write(data, count);
} else if (pipe.m_open) {
result = data::IOError::WAIT_RETRY;
} else {
result = data::IOError::BROKEN_PIPE;
}
} else {
result = data::IOError::BROKEN_PIPE;
result = data::IOError::WAIT_RETRY;
}
} else {
std::unique_lock<std::mutex> lock(pipe.m_mutex);
while (pipe.m_fifo.availableToWrite() == 0 && pipe.m_open) {
pipe.m_conditionRead.notify_one();
pipe.m_conditionWrite.wait(lock);
}
if (pipe.m_open && pipe.m_fifo.availableToWrite() > 0) {

View File

@ -48,6 +48,7 @@ public:
};
void runTests() {
OATPP_RUN_TEST(oatpp::test::base::RegRuleTest);
OATPP_RUN_TEST(oatpp::test::base::CommandLineArgumentsTest);
OATPP_RUN_TEST(oatpp::test::memory::MemoryPoolTest);
@ -61,10 +62,12 @@ void runTests() {
OATPP_RUN_TEST(oatpp::test::encoding::Base64Test);
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::web::FullAsyncTest);
}
}

View File

@ -158,8 +158,7 @@ bool MemoryLabelTest::onRun() {
}
}
}
return true;

View File

@ -49,8 +49,11 @@ bool FullAsyncTest::onRun() {
auto serverConnectionProvider = oatpp::network::virtual_::server::ConnectionProvider::createShared(interface, true);
auto clientConnectionProvider = oatpp::network::virtual_::client::ConnectionProvider::createShared(interface);
serverConnectionProvider->setSocketMaxAvailableToReadWrtie(1, 1);
clientConnectionProvider->setSocketMaxAvailableToReadWrtie(1, 1);
serverConnectionProvider->setSocketMaxAvailableToReadWrtie(123, 11);
clientConnectionProvider->setSocketMaxAvailableToReadWrtie(12421, 21312);
//serverConnectionProvider->setSocketMaxAvailableToReadWrtie(1, 1);
//clientConnectionProvider->setSocketMaxAvailableToReadWrtie(1, 1);
auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
@ -68,7 +71,7 @@ bool FullAsyncTest::onRun() {
std::thread clientThread([client, server, connectionHandler, objectMapper]{
for(v_int32 i = 0; i < 10; i ++) {
for(v_int32 i = 0; i < 1000; i ++) {
{ // test simple GET
auto response = client->getRoot();
@ -106,7 +109,9 @@ bool FullAsyncTest::onRun() {
}
auto data = stream.toString();
auto response = client->echoBody(data);
auto returnedData = response->readBodyToString();
OATPP_ASSERT(returnedData);
OATPP_ASSERT(returnedData == data);
}

View File

@ -50,9 +50,12 @@ bool FullTest::onRun() {
auto serverConnectionProvider = oatpp::network::virtual_::server::ConnectionProvider::createShared(interface);
auto clientConnectionProvider = oatpp::network::virtual_::client::ConnectionProvider::createShared(interface);
serverConnectionProvider->setSocketMaxAvailableToReadWrtie(1, 1);
clientConnectionProvider->setSocketMaxAvailableToReadWrtie(1, 1);
serverConnectionProvider->setSocketMaxAvailableToReadWrtie(123, 11);
clientConnectionProvider->setSocketMaxAvailableToReadWrtie(12421, 21312);
//serverConnectionProvider->setSocketMaxAvailableToReadWrtie(1, 1);
//clientConnectionProvider->setSocketMaxAvailableToReadWrtie(1, 1);
auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
@ -70,7 +73,7 @@ bool FullTest::onRun() {
std::thread clientThread([client, server, objectMapper]{
for(v_int32 i = 0; i < 10; i ++) {
for(v_int32 i = 0; i < 1000; i ++) {
{ // test simple GET
auto response = client->getRoot();