changeset 6802:e98c73866fcb

merge
author Alain Mazy <am@orthanc.team>
date Mon, 18 May 2026 15:15:32 +0200
parents 28466072bcb9 (current diff) 7d025f650e9f (diff)
children b28524cf93a9
files
diffstat 4 files changed, 51 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/HttpServer/BufferHttpSender.cpp	Mon May 18 15:15:19 2026 +0200
+++ b/OrthancFramework/Sources/HttpServer/BufferHttpSender.cpp	Mon May 18 15:15:32 2026 +0200
@@ -30,14 +30,34 @@
 
 namespace Orthanc
 {
+  void BufferHttpSender::ResetFromInternalBuffer()
+  {
+    if (internalBuffer_.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+    }
+    else if (internalBuffer_->empty())
+    {
+      SetBuffer(NULL, 0);
+    }
+    else
+    {
+      SetBuffer(internalBuffer_->c_str(), internalBuffer_->size());
+    }
+  }
+
+
   BufferHttpSender::BufferHttpSender() :
+    data_(NULL),
+    size_(0),
     position_(0), 
     chunkSize_(0),
     currentChunkSize_(0)
   {
   }
 
-  void BufferHttpSender::SetBuffer(const std::string& buffer)
+  void BufferHttpSender::SetBuffer(const void* data,
+                                   size_t size)
   {
     if (position_ != 0)
     {
@@ -45,25 +65,23 @@
     }
     else
     {
-      buffer_ = buffer;
+      data_ = reinterpret_cast<const char*>(data);
+      size_ = size;
     }
   }
 
+  void BufferHttpSender::SetBuffer(const std::string& buffer)
+  {
+    internalBuffer_.reset(new std::string);
+    *internalBuffer_ = buffer;
+    ResetFromInternalBuffer();
+  }
+
   void BufferHttpSender::SwapBuffer(std::string& buffer)
   {
-    if (position_ != 0)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
-    }
-    else
-    {
-      buffer_.swap(buffer);
-    }
-  }
-
-  const std::string& BufferHttpSender::GetBuffer() const
-  {
-    return buffer_;
+    internalBuffer_.reset(new std::string);
+    internalBuffer_->swap(buffer);
+    ResetFromInternalBuffer();
   }
 
   void BufferHttpSender::SetChunkSize(size_t chunkSize)
@@ -73,23 +91,23 @@
 
   uint64_t BufferHttpSender::GetContentLength()
   {
-    return buffer_.size();
+    return size_;
   }
 
 
   bool BufferHttpSender::ReadNextChunk()
   {
-    assert(position_ + currentChunkSize_ <= buffer_.size());
+    assert(position_ + currentChunkSize_ <= size_);
 
     position_ += currentChunkSize_;
 
-    if (position_ == buffer_.size())
+    if (position_ == size_)
     {
       return false;
     }
     else
     {
-      currentChunkSize_ = buffer_.size() - position_;
+      currentChunkSize_ = size_ - position_;
 
       if (chunkSize_ != 0 &&
           currentChunkSize_ > chunkSize_)
@@ -104,7 +122,7 @@
 
   const char* BufferHttpSender::GetChunkContent()
   {
-    return buffer_.c_str() + position_;
+    return data_ + position_;
   }
 
 
--- a/OrthancFramework/Sources/HttpServer/BufferHttpSender.h	Mon May 18 15:15:19 2026 +0200
+++ b/OrthancFramework/Sources/HttpServer/BufferHttpSender.h	Mon May 18 15:15:32 2026 +0200
@@ -30,21 +30,27 @@
   class ORTHANC_PUBLIC BufferHttpSender : public HttpFileSender
   {
   private:
-    std::string  buffer_;
+    std::unique_ptr<std::string>  internalBuffer_;
+
+    const char*  data_;
+    size_t       size_;
     size_t       position_;
     size_t       chunkSize_;
     size_t       currentChunkSize_;
 
+    void ResetFromInternalBuffer();
+
   public:
     BufferHttpSender();
 
+    void SetBuffer(const void* data,
+                   size_t size);
+
     void SetBuffer(const std::string& buffer);
 
     // This flavor is more efficient
     void SwapBuffer(std::string& buffer);
 
-    const std::string& GetBuffer() const;
-
     // This is for test purpose. If "chunkSize" is set to "0" (the
     // default), the entire buffer is consumed at once.
     void SetChunkSize(size_t chunkSize);
--- a/OrthancServer/Sources/ServerContext.cpp	Mon May 18 15:15:19 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Mon May 18 15:15:32 2026 +0200
@@ -1427,10 +1427,10 @@
     assert(attachment.GetContentType() == FileContentType_Dicom);
     attachmentId = attachment.GetUuid();
 
-    if (attachment.GetUncompressedSize() < largeDicomThreshold)  // release ASAP (before the read) if we don't plan to hold the lock (https://discourse.orthanc-server.org/t/patch-release-large-dicom-semaphore-lock-early-for-better-performance/6440) 
+    if (attachment.GetUncompressedSize() < largeDicomThreshold)  // release ASAP (before the read) if we don't plan to hold the lock (https://discourse.orthanc-server.org/t/patch-release-large-dicom-semaphore-lock-early-for-better-performance/6440)
     {
       largeDicomLocker.reset(NULL);
-    }    
+    }
 
     ReadAttachment(dicom, attachment, true /* uncompress */);
   }
--- a/OrthancServer/Sources/ServerContext.h	Mon May 18 15:15:19 2026 +0200
+++ b/OrthancServer/Sources/ServerContext.h	Mon May 18 15:15:32 2026 +0200
@@ -402,7 +402,7 @@
     void ReadDicomInternal(std::string& dicom,
                            const std::string& instancePublicId,
                            std::unique_ptr<Semaphore::Locker>& largeDicomLocker,
-                            std::size_t largeDicomThreshold);
+                           std::size_t largeDicomThreshold);
 
     void ReadDicomInternal(std::string& dicom,
                            std::string& attachmentId,
@@ -413,7 +413,7 @@
 public:
     void ReadDicom(std::string& dicom,
                    const std::string& instancePublicId);
- 
+
     void ReadDicom(std::string& dicom,
                    std::string& attachmentId,
                    const std::string& instancePublicId);