| 105 | } |
| 106 | |
| 107 | std::vector<std::unique_ptr<folly::IOBuf>> DestinationBuffer::getData( |
| 108 | uint64_t maxBytes, |
| 109 | int64_t sequence, |
| 110 | DataAvailableCallback notify, |
| 111 | DataConsumerActiveCheckCallback activeCheck, |
| 112 | ArbitraryBuffer* arbitraryBuffer) { |
| 113 | BOLT_CHECK_GE( |
| 114 | sequence, sequence_, "Get received for an already acknowledged item"); |
| 115 | if (arbitraryBuffer != nullptr) { |
| 116 | loadData(arbitraryBuffer, maxBytes); |
| 117 | } |
| 118 | |
| 119 | if (sequence - sequence_ > data_.size()) { |
| 120 | VLOG(1) << this << " Out of order get: " << sequence << " over " |
| 121 | << sequence_ << " Setting second notify " << notifySequence_ |
| 122 | << " / " << sequence; |
| 123 | notify_ = std::move(notify); |
| 124 | aliveCheck_ = std::move(activeCheck); |
| 125 | notifySequence_ = std::min(notifySequence_, sequence); |
| 126 | notifyMaxBytes_ = maxBytes; |
| 127 | return {}; |
| 128 | } |
| 129 | |
| 130 | if (sequence - sequence_ == data_.size()) { |
| 131 | notify_ = std::move(notify); |
| 132 | aliveCheck_ = std::move(activeCheck); |
| 133 | notifySequence_ = sequence; |
| 134 | notifyMaxBytes_ = maxBytes; |
| 135 | return {}; |
| 136 | } |
| 137 | |
| 138 | std::vector<std::unique_ptr<folly::IOBuf>> result; |
| 139 | uint64_t resultBytes = 0; |
| 140 | for (auto i = sequence - sequence_; i < data_.size(); ++i) { |
| 141 | // nullptr is used as end marker |
| 142 | if (data_[i] == nullptr) { |
| 143 | BOLT_CHECK_EQ(i, data_.size() - 1, "null marker found in the middle"); |
| 144 | result.push_back(nullptr); |
| 145 | break; |
| 146 | } |
| 147 | result.push_back(data_[i]->getIOBuf()); |
| 148 | resultBytes += data_[i]->size(); |
| 149 | if (resultBytes >= maxBytes) { |
| 150 | break; |
| 151 | } |
| 152 | } |
| 153 | return result; |
| 154 | } |
| 155 | |
| 156 | void DestinationBuffer::enqueue(std::shared_ptr<SerializedPage> data) { |
| 157 | // Drop duplicate end markers. |