[ 
https://issues.apache.org/jira/browse/MINIFICPP-1971?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17622185#comment-17622185
 ] 

Ferenc Gerlits commented on MINIFICPP-1971:
-------------------------------------------

Also, the implementation of 
\{{HTTPUploadByteArrayInputCallback::getDataChunk()}} could be improved:
{noformat}
In libminifi/src/utils/BaseHTTPClient.cpp:
> +    }
+    auto *callback = reinterpret_cast<HTTPUploadCallback *>(p);
+    return callback->setPosition(offset);
+  } catch (...) {
+    return SEEKFUNC_FAIL;
+  }
+}
+
+size_t HTTPUploadByteArrayInputCallback::getDataChunk(char *data, size_t size) 
{
+  if (stop) {
+    return HTTPRequestResponse::CALLBACK_ABORT;
+  }
+  size_t buffer_size = getBufferSize();
+  if (pos <= buffer_size) {
+    size_t len = buffer_size - pos;
+    if (len <= 0) {

< is not possible, only ==

Could be omitted if the enclosing if is modified to

if (pos < buffer_size) {



In libminifi/src/utils/BaseHTTPClient.cpp:
> +size_t HTTPUploadByteArrayInputCallback::getDataChunk(char *data, size_t 
> size) {
+  if (stop) {
+    return HTTPRequestResponse::CALLBACK_ABORT;
+  }
+  size_t buffer_size = getBufferSize();
+  if (pos <= buffer_size) {
+    size_t len = buffer_size - pos;
+    if (len <= 0) {
+      return 0;
+    }
+    auto *ptr = getBuffer(pos);
+
+    if (ptr == nullptr) {
+      return 0;
+    }
+    if (len > size)

I would use std::min instead {noformat}

> Clean up code related to HTTPUploadCallback
> -------------------------------------------
>
>                 Key: MINIFICPP-1971
>                 URL: https://issues.apache.org/jira/browse/MINIFICPP-1971
>             Project: Apache NiFi MiNiFi C++
>          Issue Type: Improvement
>    Affects Versions: 0.13.0
>            Reporter: Ferenc Gerlits
>            Priority: Minor
>
> {{HTTPUploadCallback}} and related classes are a mess.  Some problems:
> * review uses of {{seek_callback}} (set as {{CURLOPT_SEEKFUNCTION}}); when 
> does {{curl}} call this?  if {{curl}} needs this (for handling of network 
> errors, maybe?), we should support it better;
> * in {{HTTPUploadByteArrayInputCallback::setPosition()}}, the 
> {{getBufferSize() <= static_cast<size_t>(offset)}} check should probably be 
> changed to {{getBufferSize() < static_cast<size_t>(offset)}}, since seeking 
> to the end of the data is valid;
> * {{HTTPUploadByteArrayInputCallback}} and {{HttpStreamingCallback}} are both 
> callbacks for {{ProcessSession::read}} and for {{curl}}, which is confusing.  
> Since both of these store the data to be uploaded in memory, their 
> constructor could take the data in e.g. a vector, and reading the flow file 
> could be done separately and in a simpler way;
> * there is a lot of code related to stopping and closing; are these 
> useful/necessary?
> * is the multi-threading code in {{HttpStreamingCallback}} necessary, and if 
> it is, could it be done simpler?
> * could/should most (all?) usages of {{HTTPUploadByteArrayInputCallback}} be 
> replaced by {{HTTPUploadStreamContentsCallback}}?
> * etc



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to