comparison Core/HttpServer/BufferHttpSender.cpp @ 1525:f9b0169eb6bb

testing
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Aug 2015 17:50:38 +0200
parents 4a503a8c7749
children b1291df2f780
comparison
equal deleted inserted replaced
1524:4a0c2eedceb6 1525:f9b0169eb6bb
32 #include "../PrecompiledHeaders.h" 32 #include "../PrecompiledHeaders.h"
33 #include "BufferHttpSender.h" 33 #include "BufferHttpSender.h"
34 34
35 #include "../OrthancException.h" 35 #include "../OrthancException.h"
36 36
37 #include <cassert>
38
37 namespace Orthanc 39 namespace Orthanc
38 { 40 {
41 BufferHttpSender::BufferHttpSender() :
42 position_(0),
43 chunkSize_(0),
44 currentChunkSize_(0)
45 {
46 }
47
48
39 bool BufferHttpSender::ReadNextChunk() 49 bool BufferHttpSender::ReadNextChunk()
40 { 50 {
41 if (done_) 51 assert(position_ + currentChunkSize_ <= buffer_.size());
52
53 position_ += currentChunkSize_;
54
55 if (position_ == buffer_.size())
42 { 56 {
43 return false; 57 return false;
44 } 58 }
45 else 59 else
46 { 60 {
47 done_ = true; 61 currentChunkSize_ = buffer_.size() - position_;
62
63 if (chunkSize_ != 0 &&
64 currentChunkSize_ > chunkSize_)
65 {
66 currentChunkSize_ = chunkSize_;
67 }
68
48 return true; 69 return true;
49 } 70 }
50 } 71 }
51 72
73
52 const char* BufferHttpSender::GetChunkContent() 74 const char* BufferHttpSender::GetChunkContent()
53 { 75 {
54 return buffer_.c_str(); 76 return buffer_.c_str() + position_;
55 } 77 }
78
56 79
57 size_t BufferHttpSender::GetChunkSize() 80 size_t BufferHttpSender::GetChunkSize()
58 { 81 {
59 return buffer_.size(); 82 return currentChunkSize_;
60 } 83 }
61 } 84 }