IO - Errors refactored

This commit is contained in:
lganzzzo 2019-02-07 02:57:27 +02:00
parent c4dfd04505
commit 3863857700
8 changed files with 36 additions and 41 deletions

View File

@ -138,7 +138,7 @@ oatpp::data::v_io_size transfer(const std::shared_ptr<InputStream>& fromStream,
}
progress += readResult;
} else {
if(readResult == oatpp::data::stream::Errors::ERROR_IO_RETRY || readResult == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
if(readResult == data::IOError::RETRY || readResult == data::IOError::WAIT_RETRY) {
continue;
}
return progress;
@ -246,11 +246,11 @@ oatpp::async::Action writeSomeDataAsyncInline(oatpp::data::stream::OutputStream*
data::v_io_size& size,
const oatpp::async::Action& nextAction) {
auto res = stream->write(data, size);
if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
if(res == data::IOError::WAIT_RETRY) {
return oatpp::async::Action::_WAIT_RETRY;
} else if(res == oatpp::data::stream::Errors::ERROR_IO_RETRY) {
} else if(res == data::IOError::RETRY) {
return oatpp::async::Action::_REPEAT;
} else if(res == oatpp::data::stream::Errors::ERROR_IO_PIPE) {
} 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));
@ -268,11 +268,11 @@ oatpp::async::Action writeExactSizeDataAsyncInline(oatpp::data::stream::OutputSt
data::v_io_size& size,
const oatpp::async::Action& nextAction) {
auto res = stream->write(data, size);
if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
if(res == data::IOError::WAIT_RETRY) {
return oatpp::async::Action::_WAIT_RETRY;
} else if(res == oatpp::data::stream::Errors::ERROR_IO_RETRY) {
} else if(res == data::IOError::RETRY) {
return oatpp::async::Action::_REPEAT;
} else if(res == oatpp::data::stream::Errors::ERROR_IO_PIPE) {
} 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));
@ -292,9 +292,9 @@ oatpp::async::Action readSomeDataAsyncInline(oatpp::data::stream::InputStream* s
data::v_io_size& bytesLeftToRead,
const oatpp::async::Action& nextAction) {
auto res = stream->read(data, bytesLeftToRead);
if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
if(res == data::IOError::WAIT_RETRY) {
return oatpp::async::Action::_WAIT_RETRY;
} else if(res == oatpp::data::stream::Errors::ERROR_IO_RETRY) {
} else if(res == data::IOError::RETRY) {
return oatpp::async::Action::_REPEAT;
} else if( res < 0) {
return oatpp::async::Action(oatpp::async::Error(Errors::ERROR_ASYNC_FAILED_TO_READ_DATA));
@ -310,11 +310,11 @@ oatpp::async::Action readExactSizeDataAsyncInline(oatpp::data::stream::InputStre
data::v_io_size& bytesLeftToRead,
const oatpp::async::Action& nextAction) {
auto res = stream->read(data, bytesLeftToRead);
if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
if(res == data::IOError::WAIT_RETRY) {
return oatpp::async::Action::_WAIT_RETRY;
} else if(res == oatpp::data::stream::Errors::ERROR_IO_RETRY) {
} else if(res == data::IOError::RETRY) {
return oatpp::async::Action::_REPEAT;
} else if(res == oatpp::data::stream::Errors::ERROR_IO_PIPE) {
} 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_READ_DATA));
@ -341,7 +341,7 @@ oatpp::data::v_io_size readExactSizeData(oatpp::data::stream::InputStream* strea
if(res > 0) {
progress += res;
} else { // if res == 0 then probably stream handles read() error incorrectly. return.
if(res == oatpp::data::stream::Errors::ERROR_IO_RETRY || res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
if(res == data::IOError::RETRY || res == data::IOError::WAIT_RETRY) {
continue;
}
return progress;
@ -365,7 +365,7 @@ oatpp::data::v_io_size writeExactSizeData(oatpp::data::stream::OutputStream* str
if(res > 0) {
progress += res;
} else { // if res == 0 then probably stream handles write() error incorrectly. return.
if(res == oatpp::data::stream::Errors::ERROR_IO_RETRY || res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
if(res == data::IOError::RETRY || res == data::IOError::WAIT_RETRY) {
continue;
}
return progress;

View File

@ -34,11 +34,6 @@ namespace oatpp { namespace data{ namespace stream {
class Errors {
public:
constexpr static data::v_io_size ERROR_IO_NOTHING_TO_READ = -1001;
constexpr static data::v_io_size ERROR_IO_WAIT_RETRY = -1002;
constexpr static data::v_io_size ERROR_IO_RETRY = -1003;
constexpr static data::v_io_size ERROR_IO_PIPE = -1004;
static const char* const ERROR_ASYNC_FAILED_TO_WRITE_DATA;
static const char* const ERROR_ASYNC_FAILED_TO_READ_DATA;
};

View File

@ -122,12 +122,12 @@ oatpp::async::Action OutputStreamBufferedProxy::flushAsync(oatpp::async::Abstrac
m_stream->m_pos = 0;
m_stream->m_posEnd = 0;
return finish();
} else if(result == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
} else if(result == data::IOError::WAIT_RETRY) {
return oatpp::async::Action::_WAIT_RETRY;
} else if(result == oatpp::data::stream::Errors::ERROR_IO_RETRY) {
} else if(result == data::IOError::RETRY) {
return oatpp::async::Action::_REPEAT;
} else if(result == oatpp::data::stream::Errors::ERROR_IO_PIPE) {
return error("[oatpp::data::stream::OutputStreamBufferedProxy::flushAsync()]: Error - oatpp::data::stream::Errors::ERROR_IO_PIPE");
} else if(result == data::IOError::BROKEN_PIPE) {
return error("[oatpp::data::stream::OutputStreamBufferedProxy::flushAsync()]: Error - data::IOError::BROKEN_PIPE");
} else if( result < 0) {
return error("[oatpp::data::stream::OutputStreamBufferedProxy::flushAsync()]: Error - Failed to flush all data");
} else if(result < amount) {

View File

@ -53,11 +53,11 @@ data::v_io_size Connection::write(const void *buff, data::v_io_size count){
if(result <= 0) {
auto e = errno;
if(e == EAGAIN || e == EWOULDBLOCK){
return oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY; // For async io. In case socket is non_blocking
return data::IOError::WAIT_RETRY; // For async io. In case socket is non_blocking
} else if(e == EINTR) {
return oatpp::data::stream::Errors::ERROR_IO_RETRY;
return data::IOError::RETRY;
} else if(e == EPIPE) {
return oatpp::data::stream::Errors::ERROR_IO_PIPE;
return data::IOError::BROKEN_PIPE;
} else {
//OATPP_LOGD("Connection", "write errno=%d", e);
}
@ -71,11 +71,11 @@ data::v_io_size Connection::read(void *buff, data::v_io_size count){
if(result <= 0) {
auto e = errno;
if(e == EAGAIN || e == EWOULDBLOCK){
return oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY; // For async io. In case socket is non_blocking
return data::IOError::WAIT_RETRY; // For async io. In case socket is non_blocking
} else if(e == EINTR) {
return oatpp::data::stream::Errors::ERROR_IO_RETRY;
return data::IOError::RETRY;
} else if(e == ECONNRESET) {
return oatpp::data::stream::Errors::ERROR_IO_PIPE;
return data::IOError::BROKEN_PIPE;
} else {
//OATPP_LOGD("Connection", "write errno=%d", e);
}

View File

@ -43,9 +43,9 @@ data::v_io_size Pipe::Reader::read(void *data, data::v_io_size count) {
if(pipe.m_buffer.availableToRead() > 0) {
result = pipe.m_buffer.read(data, count);
} else if(pipe.m_open) {
result = oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY;
result = data::IOError::WAIT_RETRY;
} else {
result = oatpp::data::stream::Errors::ERROR_IO_PIPE;
result = data::IOError::BROKEN_PIPE;
}
} else {
std::unique_lock<std::mutex> lock(pipe.m_mutex);
@ -56,7 +56,7 @@ data::v_io_size Pipe::Reader::read(void *data, data::v_io_size count) {
if (pipe.m_buffer.availableToRead() > 0) {
result = pipe.m_buffer.read(data, count);
} else {
result = oatpp::data::stream::Errors::ERROR_IO_PIPE;
result = data::IOError::BROKEN_PIPE;
}
}
@ -83,9 +83,9 @@ data::v_io_size Pipe::Writer::write(const void *data, data::v_io_size count) {
if(pipe.m_buffer.availableToWrite() > 0) {
result = pipe.m_buffer.write(data, count);
} else if(pipe.m_open) {
result = oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY;
result = data::IOError::WAIT_RETRY;
} else {
result = oatpp::data::stream::Errors::ERROR_IO_PIPE;
result = data::IOError::BROKEN_PIPE;
}
} else {
std::unique_lock<std::mutex> lock(pipe.m_mutex);
@ -96,7 +96,7 @@ data::v_io_size Pipe::Writer::write(const void *data, data::v_io_size count) {
if (pipe.m_open && pipe.m_buffer.availableToWrite() > 0) {
result = pipe.m_buffer.write(data, count);
} else {
result = oatpp::data::stream::Errors::ERROR_IO_PIPE;
result = data::IOError::BROKEN_PIPE;
}
}

View File

@ -60,7 +60,7 @@ data::v_io_size RequestHeadersReader::readHeadersSection(const std::shared_ptr<o
}
}
} else if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY || res == oatpp::data::stream::Errors::ERROR_IO_RETRY) {
} else if(res == data::IOError::WAIT_RETRY || res == data::IOError::RETRY) {
continue;
} else {
break;
@ -148,7 +148,7 @@ RequestHeadersReader::Action RequestHeadersReader::readHeadersAsync(oatpp::async
return waitRetry();
} else if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY || res == oatpp::data::stream::Errors::ERROR_IO_RETRY) {
} else if(res == data::IOError::WAIT_RETRY || res == data::IOError::RETRY) {
return waitRetry();
} else {
return abort();

View File

@ -60,7 +60,7 @@ data::v_io_size ResponseHeadersReader::readHeadersSection(const std::shared_ptr<
}
}
} else if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY || res == oatpp::data::stream::Errors::ERROR_IO_RETRY) {
} else if(res == data::IOError::WAIT_RETRY || res == data::IOError::RETRY) {
continue;
} else {
break;
@ -148,7 +148,7 @@ ResponseHeadersReader::Action ResponseHeadersReader::readHeadersAsync(oatpp::asy
return waitRetry();
} else if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY || res == oatpp::data::stream::Errors::ERROR_IO_RETRY) {
} else if(res == data::IOError::WAIT_RETRY || res == data::IOError::RETRY) {
return waitRetry();
} else {
return abort();

View File

@ -152,9 +152,9 @@ oatpp::async::Action SimpleBodyDecoder::doChunkedDecodingAsync(oatpp::async::Abs
Action readLineChar() {
auto res = m_fromStream->read(&m_lineChar, 1);
if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
if(res == data::IOError::WAIT_RETRY) {
return oatpp::async::Action::_WAIT_RETRY;
} else if(res == oatpp::data::stream::Errors::ERROR_IO_RETRY) {
} else if(res == data::IOError::RETRY) {
return oatpp::async::Action::_REPEAT;
} else if( res < 0) {
return error("[BodyDecoder::ChunkedDecoder] Can't read line char");