martinzink commented on code in PR #1383:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1383#discussion_r946588904
##########
libminifi/include/utils/BaseHTTPClient.h:
##########
@@ -51,38 +39,43 @@ struct HTTPProxy {
int port = 0;
};
-struct HTTPUploadCallback {
- HTTPUploadCallback() {
- stop = false;
- ptr = nullptr;
- pos = 0;
- }
- std::mutex mutex;
- std::atomic<bool> stop;
- ByteInputCallback *ptr;
- size_t pos;
+class HTTPUploadCallback {
+ public:
+ explicit HTTPUploadCallback(ByteInputCallback* byte_input_callback) :
ptr(std::move(byte_input_callback)) {}
size_t getPos() {
std::lock_guard<std::mutex> lock(mutex);
return pos;
Review Comment:
good idea, reworked them in
https://github.com/apache/nifi-minifi-cpp/pull/1383/commits/4263282eb39be5757f303a61bb0d5380be157d66
##########
libminifi/include/utils/BaseHTTPClient.h:
##########
@@ -51,38 +39,43 @@ struct HTTPProxy {
int port = 0;
};
-struct HTTPUploadCallback {
Review Comment:
good idea, reworked them in
https://github.com/apache/nifi-minifi-cpp/pull/1383/commits/4263282eb39be5757f303a61bb0d5380be157d66
##########
extensions/http-curl/client/HTTPStream.cpp:
##########
@@ -26,55 +26,56 @@
#include "io/validation.h"
#include "utils/gsl.h"
-namespace org {
-namespace apache {
-namespace nifi {
-namespace minifi {
-namespace io {
+namespace org::apache::nifi::minifi::extensions::curl {
-HttpStream::HttpStream(std::shared_ptr<utils::HTTPClient> client)
+HttpStream::HttpStream(std::shared_ptr<HTTPClient> client)
: http_client_(std::move(client)),
written(0),
- // given the nature of the stream we don't want to slow libCURL, we will
produce
- // a warning instead allowing us to adjust it server side or through the
local configuration.
- http_read_callback_(66560, true),
+ // given the nature of the stream we don't want to slow libCURL, we will
produce
+ // a warning instead allowing us to adjust it server side or through the
local configuration.
started_(false) {
// submit early on
}
void HttpStream::close() {
- http_callback_.close();
- http_read_callback_.close();
+ if (auto read_callback = http_client_->getReadCallback())
+ read_callback->getPtr()->close();
+ if (auto upload_callback = http_client_->getUploadCallback())
+ upload_callback->getPtr()->close();
}
void HttpStream::seek(size_t /*offset*/) {
// seek is an unnecessary part of this implementation
throw std::logic_error{"HttpStream::seek is unimplemented"};
}
-size_t HttpStream::tell() const {
+size_t HttpStream::tell() const {
// tell is an unnecessary part of this implementation
throw std::logic_error{"HttpStream::tell is unimplemented"};
}
// data stream overrides
-size_t HttpStream::write(const uint8_t *value, size_t size) {
+size_t HttpStream::write(const uint8_t* value, size_t size) {
if (size == 0) return 0;
if (IsNullOrEmpty(value)) {
- return STREAM_ERROR;
+ return io::STREAM_ERROR;
}
if (!started_) {
std::lock_guard<std::mutex> lock(mutex_);
if (!started_) {
- callback_.ptr = &http_callback_;
- callback_.pos = 0;
- http_client_->setUploadCallback(&callback_);
+ auto callback = std::make_unique<utils::HTTPUploadCallback>(new
HttpStreamingCallback());
+ callback->pos = 0;
+ http_client_->setUploadCallback(std::move(callback));
http_client_future_ = std::async(std::launch::async, submit_client,
http_client_);
started_ = true;
}
}
- http_callback_.process(value, size);
+ auto http_callback =
dynamic_cast<HttpStreamingCallback*>(gsl::as_nullable(http_client_->getUploadCallback()->getPtr()));
+ if (http_callback)
Review Comment:
good idea, merged them in
https://github.com/apache/nifi-minifi-cpp/commit/4263282eb39be5757f303a61bb0d5380be157d66#diff-4e08bc45485eac46e59652e031a79a51dca96dc3a08fa5bf6ee8d2b5603bda6eR74
##########
extensions/http-curl/client/HTTPStream.cpp:
##########
@@ -26,55 +26,56 @@
#include "io/validation.h"
#include "utils/gsl.h"
-namespace org {
-namespace apache {
-namespace nifi {
-namespace minifi {
-namespace io {
+namespace org::apache::nifi::minifi::extensions::curl {
-HttpStream::HttpStream(std::shared_ptr<utils::HTTPClient> client)
+HttpStream::HttpStream(std::shared_ptr<HTTPClient> client)
: http_client_(std::move(client)),
written(0),
- // given the nature of the stream we don't want to slow libCURL, we will
produce
- // a warning instead allowing us to adjust it server side or through the
local configuration.
- http_read_callback_(66560, true),
+ // given the nature of the stream we don't want to slow libCURL, we will
produce
+ // a warning instead allowing us to adjust it server side or through the
local configuration.
started_(false) {
// submit early on
}
void HttpStream::close() {
- http_callback_.close();
- http_read_callback_.close();
+ if (auto read_callback = http_client_->getReadCallback())
+ read_callback->getPtr()->close();
+ if (auto upload_callback = http_client_->getUploadCallback())
+ upload_callback->getPtr()->close();
}
void HttpStream::seek(size_t /*offset*/) {
// seek is an unnecessary part of this implementation
throw std::logic_error{"HttpStream::seek is unimplemented"};
}
-size_t HttpStream::tell() const {
+size_t HttpStream::tell() const {
// tell is an unnecessary part of this implementation
throw std::logic_error{"HttpStream::tell is unimplemented"};
}
// data stream overrides
-size_t HttpStream::write(const uint8_t *value, size_t size) {
+size_t HttpStream::write(const uint8_t* value, size_t size) {
if (size == 0) return 0;
if (IsNullOrEmpty(value)) {
- return STREAM_ERROR;
+ return io::STREAM_ERROR;
}
if (!started_) {
std::lock_guard<std::mutex> lock(mutex_);
if (!started_) {
- callback_.ptr = &http_callback_;
- callback_.pos = 0;
- http_client_->setUploadCallback(&callback_);
+ auto callback = std::make_unique<utils::HTTPUploadCallback>(new
HttpStreamingCallback());
Review Comment:
now that it is inheritance I could make it simpler
https://github.com/apache/nifi-minifi-cpp/commit/4263282eb39be5757f303a61bb0d5380be157d66#diff-4e08bc45485eac46e59652e031a79a51dca96dc3a08fa5bf6ee8d2b5603bda6eR67
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]