Skip to content

Commit

Permalink
Increase oatpp version to 0.19.12
Browse files Browse the repository at this point in the history
  • Loading branch information
lganzzzo committed Jan 11, 2020
1 parent 5354e78 commit ef94f5b
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 94 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
## use these variables to configure module installation

set(OATPP_THIS_MODULE_NAME oatpp-curl) ## name of the module (also name of folders in installation dirs)
set(OATPP_THIS_MODULE_VERSION "0.19.11") ## version of the module (also sufix of folders in installation dirs)
set(OATPP_THIS_MODULE_VERSION "0.19.12") ## version of the module (also sufix of folders in installation dirs)
set(OATPP_THIS_MODULE_LIBRARIES oatpp-curl) ## list of libraries to find when find_package is called
set(OATPP_THIS_MODULE_TARGETS oatpp-curl) ## list of targets to install
set(OATPP_THIS_MODULE_DIRECTORIES oatpp-curl) ## list of directories to install
Expand Down
4 changes: 2 additions & 2 deletions src/oatpp-curl/RequestExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ RequestExecutor::executeOnceAsync(const String& method,

Action act() override {
if(m_body) {
return m_body->writeToStreamAsync(std::make_shared<io::BodyOutputStream>(m_writer, oatpp::data::stream::IOMode::NON_BLOCKING))
return m_body->writeToStreamAsync(std::make_shared<io::BodyOutputStream>(m_writer, oatpp::data::stream::IOMode::ASYNCHRONOUS))
.next(yieldTo(&ExecutorCoroutine::doPerform));
}
return yieldTo(&ExecutorCoroutine::doPerform);
Expand All @@ -202,7 +202,7 @@ RequestExecutor::executeOnceAsync(const String& method,

auto line = m_headersReader->getStartingLine();
auto responseHeaders = m_headersReader->getHeaders();
auto bodyStream = std::make_shared<io::BodyInputStream>(m_reader, oatpp::data::stream::IOMode::NON_BLOCKING);
auto bodyStream = std::make_shared<io::BodyInputStream>(m_reader, oatpp::data::stream::IOMode::ASYNCHRONOUS);

return _return(Response::createShared(line.statusCode, line.description.toString(), responseHeaders, bodyStream, m_bodyDecoder));

Expand Down
2 changes: 1 addition & 1 deletion src/oatpp-curl/io/BodyDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void BodyDecoder::decode(const Headers& headers,

oatpp::async::CoroutineStarter BodyDecoder::decodeAsync(const oatpp::web::protocol::http::Headers& headers,
const std::shared_ptr<oatpp::data::stream::InputStream>& bodyStream,
const std::shared_ptr<data::stream::AsyncWriteCallback>& writeCallback) const
const std::shared_ptr<data::stream::WriteCallback>& writeCallback) const
{
auto buffer = oatpp::data::buffer::IOBuffer::createShared();
return oatpp::data::stream::transferAsync(bodyStream, writeCallback, 0, buffer);
Expand Down
4 changes: 2 additions & 2 deletions src/oatpp-curl/io/BodyDecoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ class BodyDecoder : public oatpp::web::protocol::http::incoming::BodyDecoder {
* Curl already did all decoding.
* @param headers - Headers map. &id:oatpp::web::protocol::http::Headers;.
* @param bodyStream - `std::shared_ptr` to &id:oatpp::data::stream::InputStream;.
* @param writeCallback - `std::shared_ptr` to &id:oatpp::data::stream::AsyncWriteCallback;.
* @param writeCallback - `std::shared_ptr` to &id:oatpp::data::stream::WriteCallback;.
* @return - &id:oatpp::async::CoroutineStarter;.
*/
virtual oatpp::async::CoroutineStarter decodeAsync(const Headers& headers,
const std::shared_ptr<data::stream::InputStream>& bodyStream,
const std::shared_ptr<data::stream::AsyncWriteCallback>& writeCallback) const override;
const std::shared_ptr<data::stream::WriteCallback>& writeCallback) const override;

};

Expand Down
22 changes: 3 additions & 19 deletions src/oatpp-curl/io/BodyInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,15 @@ BodyInputStream::BodyInputStream(const std::shared_ptr<CurlBodyReader> reader, o
, m_ioMode(ioMode)
{}

data::v_io_size BodyInputStream::read(void *data, v_buff_size count) {
if(m_ioMode == oatpp::data::stream::IOMode::NON_BLOCKING) {
v_io_size BodyInputStream::read(void *data, v_buff_size count, async::Action& action) {
if(m_ioMode == oatpp::data::stream::IOMode::ASYNCHRONOUS) {
// No Action. Just return IOError::RETRY_READ in case no data is available.
return m_reader->readNonBlocking(data, count);
} else {
return m_reader->read(data, count);
}
}

oatpp::async::Action BodyInputStream::suggestInputStreamAction(data::v_io_size ioResult) {

if(ioResult > 0) {
return oatpp::async::Action::createActionByType(oatpp::async::Action::TYPE_REPEAT);
}

switch (ioResult) {
case oatpp::data::IOError::WAIT_RETRY_READ:
return oatpp::async::Action::createWaitRepeatAction(oatpp::base::Environment::getMicroTickCount() + 100 * 1000);
case oatpp::data::IOError::RETRY_READ:
return oatpp::async::Action::createActionByType(oatpp::async::Action::TYPE_REPEAT);
}

throw std::runtime_error("[oatpp::curl::io::BodyInputStream::suggestInputStreamAction()]: Error. Unable to suggest async action for I/O result.");

}

void BodyInputStream::setInputStreamIOMode(oatpp::data::stream::IOMode ioMode) {
m_ioMode = ioMode;
}
Expand Down
12 changes: 2 additions & 10 deletions src/oatpp-curl/io/BodyInputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,9 @@ class BodyInputStream : public oatpp::data::stream::InputStream {
* Read data from stream. Implementation of &id:oatpp::data::stream::InputStream::read; method.
* @param data - buffer to read data to.
* @param count - buffer size.
* @return - &id:oatpp::data::v_io_size;.
* @return - &id:oatpp::v_io_size;.
*/
data::v_io_size read(void *data, v_buff_size count) override;

/**
* Implementation of InputStream must suggest async actions for I/O results.
* Suggested Action is used for scheduling coroutines in async::Executor.
* @param ioResult - result of the call to &l:InputStream::read ();.
* @return - &id:oatpp::async::Action;.
*/
oatpp::async::Action suggestInputStreamAction(data::v_io_size ioResult) override;
v_io_size read(void *data, v_buff_size count, async::Action& action) override;

/**
* Set stream I/O mode.
Expand Down
24 changes: 3 additions & 21 deletions src/oatpp-curl/io/BodyOutputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,19 @@ BodyOutputStream::BodyOutputStream(const std::shared_ptr<CurlBodyWriter> writer,
, m_ioMode(ioMode)
{}

data::v_io_size BodyOutputStream::write(const void *data, v_buff_size count) {
if(m_ioMode == oatpp::data::stream::IOMode::NON_BLOCKING) {
v_io_size BodyOutputStream::write(const void *data, v_buff_size count, async::Action& action) {
if(m_ioMode == oatpp::data::stream::IOMode::ASYNCHRONOUS) {
// No Action. Just return IOError::RETRY_WRITE in case no data is available.
return m_writer->writeNonBlocking(data, count);
} else {
return m_writer->write(data, count);
}
}

oatpp::async::Action BodyOutputStream::suggestOutputStreamAction(data::v_io_size ioResult) {

if(ioResult > 0) {
return oatpp::async::Action::createActionByType(oatpp::async::Action::TYPE_REPEAT);
}

switch (ioResult) {
case oatpp::data::IOError::WAIT_RETRY_WRITE:
return oatpp::async::Action::createWaitRepeatAction(oatpp::base::Environment::getMicroTickCount() + 100 * 1000);
case oatpp::data::IOError::RETRY_WRITE:
return oatpp::async::Action::createActionByType(oatpp::async::Action::TYPE_REPEAT);
}

throw std::runtime_error("[oatpp::curl::io::BodyOutputStream::suggestInputStreamAction()]: Error. Unable to suggest async action for I/O result.");

}


void BodyOutputStream::setOutputStreamIOMode(oatpp::data::stream::IOMode ioMode) {
m_ioMode = ioMode;
}


oatpp::data::stream::IOMode BodyOutputStream::getOutputStreamIOMode() {
return m_ioMode;
}
Expand Down
12 changes: 2 additions & 10 deletions src/oatpp-curl/io/BodyOutputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,9 @@ class BodyOutputStream : public oatpp::data::stream::OutputStream {
* Write data to stream. Implementation of &id:oatpp::data::stream::OutputStream::write; method.
* @param data - data to write.
* @param count - data size.
* @return - actual amount of bytes written. &id:oatpp::data::v_io_size;.
* @return - actual amount of bytes written. &id:oatpp::v_io_size;.
*/
data::v_io_size write(const void *data, v_buff_size count) override;

/**
* Implementation of OutputStream must suggest async actions for I/O results.
* Suggested Action is used for scheduling coroutines in async::Executor.
* @param ioResult - result of the call to &l:OutputStream::write ();.
* @return - &id:oatpp::async::Action;.
*/
oatpp::async::Action suggestOutputStreamAction(data::v_io_size ioResult) override;
v_io_size write(const void *data, v_buff_size count, async::Action& action) override;

/**
* Set OutputStream I/O mode.
Expand Down
18 changes: 9 additions & 9 deletions src/oatpp-curl/io/CurlBodyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ size_t CurlBodyReader::writeCallback(char *ptr, size_t size, size_t nmemb, void
instance->m_buffer.clear();
instance->m_position = 0;
}
return instance->m_buffer.write(ptr, size * nmemb);
return instance->m_buffer.writeSimple(ptr, size * nmemb);
}

CurlBodyReader::CurlBodyReader(const std::shared_ptr<CurlHandles>& curlHandles)
Expand All @@ -54,17 +54,17 @@ CurlBodyReader::CurlBodyReader(const std::shared_ptr<CurlHandles>& curlHandles)
curl_easy_setopt(m_handles->getEasyHandle(), CURLOPT_WRITEDATA, this);
}

data::v_io_size CurlBodyReader::read(void *data, data::v_io_size count) {
data::v_io_size readCount;
while ((readCount = readNonBlocking(data, count)) == oatpp::data::IOError::WAIT_RETRY_READ) {
v_io_size CurlBodyReader::read(void *data, v_io_size count) {
v_io_size readCount;
while ((readCount = readNonBlocking(data, count)) == oatpp::IOError::RETRY_READ) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return readCount;
}

data::v_io_size CurlBodyReader::readNonBlocking(void *data, data::v_io_size count) {
v_io_size CurlBodyReader::readNonBlocking(void *data, v_io_size count) {

data::v_io_size availableBytes = getAvailableBytesCount();
v_io_size availableBytes = getAvailableBytesCount();

if(availableBytes == 0) {

Expand All @@ -76,9 +76,9 @@ data::v_io_size CurlBodyReader::readNonBlocking(void *data, data::v_io_size coun
if(availableBytes == 0) {

if(still_running) {
return oatpp::data::IOError::WAIT_RETRY_READ;
return oatpp::IOError::RETRY_READ;
} else {
return oatpp::data::IOError::BROKEN_PIPE;
return oatpp::IOError::BROKEN_PIPE;
}

}
Expand All @@ -91,7 +91,7 @@ data::v_io_size CurlBodyReader::readNonBlocking(void *data, data::v_io_size coun

}

data::v_io_size CurlBodyReader::getAvailableBytesCount() {
v_io_size CurlBodyReader::getAvailableBytesCount() {
return m_buffer.getSize() - m_position;
}

Expand Down
14 changes: 7 additions & 7 deletions src/oatpp-curl/io/CurlBodyReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CurlBodyReader {
private:
std::shared_ptr<CurlHandles> m_handles;
oatpp::data::stream::ChunkedBuffer m_buffer;
data::v_io_size m_position;
v_io_size m_position;
private:
static size_t writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata);
public:
Expand All @@ -53,23 +53,23 @@ class CurlBodyReader {
* Read body data.
* @param data - buffer to read data to.
* @param count - buffer size.
* @return - actual amount of bytes read. &id:oatpp::data::v_io_size;.
* @return - actual amount of bytes read. &id:oatpp::v_io_size;.
*/
data::v_io_size read(void *data, data::v_io_size count);
v_io_size read(void *data, v_io_size count);

/**
* Non blocking attempt to Read body data.
* @param data - buffer to read data to.
* @param count - buffer size.
* @return - actual amount of bytes read. &id:oatpp::data::v_io_size;.
* @return - actual amount of bytes read. &id:oatpp::v_io_size;.
*/
data::v_io_size readNonBlocking(void *data, data::v_io_size count);
v_io_size readNonBlocking(void *data, v_io_size count);

/**
* Available amount of bytes currently buffered.
* @return - &id:oatpp::data::v_io_size;.
* @return - &id:oatpp::v_io_size;.
*/
data::v_io_size getAvailableBytesCount();
v_io_size getAvailableBytesCount();

};

Expand Down
12 changes: 6 additions & 6 deletions src/oatpp-curl/io/CurlBodyWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ CurlBodyWriter::CurlBodyWriter(const std::shared_ptr<CurlHandles>& curlHandles)
curl_easy_setopt(m_handles->getEasyHandle(), CURLOPT_READDATA, this);
}

data::v_io_size CurlBodyWriter::write(const void *data, data::v_io_size count) {
v_io_size CurlBodyWriter::write(const void *data, v_io_size count) {

data::v_io_size writeCount;
while ((writeCount = writeNonBlocking(data, count)) == oatpp::data::IOError::WAIT_RETRY_WRITE) {
v_io_size writeCount;
while ((writeCount = writeNonBlocking(data, count)) == oatpp::IOError::RETRY_WRITE) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return writeCount;

}

data::v_io_size CurlBodyWriter::writeNonBlocking(const void *data, data::v_io_size count) {
v_io_size CurlBodyWriter::writeNonBlocking(const void *data, v_io_size count) {

m_currentData = data;
m_currentDataSize = count;
Expand All @@ -75,10 +75,10 @@ data::v_io_size CurlBodyWriter::writeNonBlocking(const void *data, data::v_io_si
if(m_currentData == nullptr) {
return m_currentDataSize;
} else if(still_running) {
return oatpp::data::IOError::WAIT_RETRY_WRITE;
return oatpp::IOError::RETRY_WRITE;
}

return oatpp::data::IOError::BROKEN_PIPE;
return oatpp::IOError::BROKEN_PIPE;

}

Expand Down
10 changes: 5 additions & 5 deletions src/oatpp-curl/io/CurlBodyWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CurlBodyWriter {
private:
std::shared_ptr<CurlHandles> m_handles;
const void* m_currentData;
data::v_io_size m_currentDataSize;
v_io_size m_currentDataSize;
private:
static size_t readCallback(char *buffer, size_t size, size_t nitems, void *userdata);
public:
Expand All @@ -55,17 +55,17 @@ class CurlBodyWriter {
* Write data to body.
* @param data - pointer to data to write.
* @param count - data size.
* @return - actual amount of bytes written. &id:oatpp::data::v_io_size;.
* @return - actual amount of bytes written. &id:oatpp::v_io_size;.
*/
data::v_io_size write(const void *data, data::v_io_size count);
v_io_size write(const void *data, v_io_size count);

/**
* Non blocking attempt to write data to body.
* @param data - pointer to data to write.
* @param count - data size.
* @return - actual amount of bytes written. &id:oatpp::data::v_io_size;.
* @return - actual amount of bytes written. &id:oatpp::v_io_size;.
*/
data::v_io_size writeNonBlocking(const void *data, data::v_io_size count);
v_io_size writeNonBlocking(const void *data, v_io_size count);

};

Expand Down
2 changes: 1 addition & 1 deletion src/oatpp-curl/io/CurlHeadersReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CurlHeadersReader {
constexpr static v_int32 STATE_FINISHED = 2;
private:
std::shared_ptr<CurlHandles> m_handles;
data::v_io_size m_position;
v_io_size m_position;
v_int32 m_state;
oatpp::web::protocol::http::Headers m_headers;
oatpp::web::protocol::http::ResponseStartingLine m_startingLine;
Expand Down

0 comments on commit ef94f5b

Please sign in to comment.