Skip to content

Commit

Permalink
update to the latest oatpp API.
Browse files Browse the repository at this point in the history
  • Loading branch information
lganzzzo committed Nov 16, 2021
1 parent c12b7b3 commit 060629f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/oatpp-curl/io/CurlBodyReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ size_t CurlBodyReader::writeCallback(char *ptr, size_t size, size_t nmemb, void
CurlBodyReader* instance = static_cast<CurlBodyReader*>(userdata);

if(instance->m_position != 0) {
if(instance->m_position != instance->m_buffer.getSize()){
if(instance->m_position != instance->m_buffer.getCurrentPosition()){
throw std::runtime_error("[oatpp::curl::CurlBodyReader::writeCallback(...)]: Invalid state.");
}
instance->m_buffer.clear();
instance->m_buffer.setCurrentPosition(0);
instance->m_position = 0;
}
return instance->m_buffer.writeSimple(ptr, size * nmemb);
Expand Down Expand Up @@ -84,15 +84,19 @@ v_io_size CurlBodyReader::readNonBlocking(void *data, v_io_size count) {
}

}

auto readCount = m_buffer.readSubstring(data, m_position, count);

v_int64 readCount = count;
if(count + m_position > m_buffer.getCurrentPosition()) {
readCount = m_buffer.getCurrentPosition() - m_position;
}
std::memcpy(data, m_buffer.getData() + m_position, readCount);
m_position += readCount;
return readCount;

}

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

}}}
4 changes: 2 additions & 2 deletions src/oatpp-curl/io/CurlBodyReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "./Curl.hpp"

#include "oatpp/core/data/stream/ChunkedBuffer.hpp"
#include "oatpp/core/data/stream/BufferStream.hpp"

namespace oatpp { namespace curl { namespace io {

Expand All @@ -37,7 +37,7 @@ namespace oatpp { namespace curl { namespace io {
class CurlBodyReader {
private:
std::shared_ptr<CurlHandles> m_handles;
oatpp::data::stream::ChunkedBuffer m_buffer;
oatpp::data::stream::BufferOutputStream m_buffer;
v_io_size m_position;
private:
static size_t writeCallback(char *ptr, size_t size, size_t nmemb, void *userdata);
Expand Down
4 changes: 2 additions & 2 deletions src/oatpp-curl/io/CurlHeadersReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "./Curl.hpp"

#include "oatpp/web/protocol/http/Http.hpp"
#include "oatpp/core/data/stream/ChunkedBuffer.hpp"
#include "oatpp/core/data/stream/BufferStream.hpp"

namespace oatpp { namespace curl { namespace io {

Expand Down Expand Up @@ -59,7 +59,7 @@ class CurlHeadersReader {
v_int32 m_state;
oatpp::web::protocol::http::Headers m_headers;
oatpp::web::protocol::http::ResponseStartingLine m_startingLine;
oatpp::data::stream::ChunkedBuffer m_buffer;
oatpp::data::stream::BufferOutputStream m_buffer;
private:
static size_t headerCallback(char *ptr, size_t size, size_t nmemb, void *userdata);
public:
Expand Down

0 comments on commit 060629f

Please sign in to comment.