File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -320,11 +320,34 @@ class MutIOBuf : public IOBuf {
320320
321321 template <typename T> T& GetNoAdvance () {
322322 assert (p_->Length () > 0 );
323+
324+ #ifdef __EBBRT_ENABLE_BAREMETAL_NIC__
325+ if (p_->Length () - offset_ < sizeof (T)) {
326+ // request straddles buffers, allocate a new chunk of memory to copy it
327+ // into (so it is contiguous)
328+ chunk_list.emplace_front ();
329+ auto & chunk = chunk_list.front ();
330+ chunk.reserve (sizeof (T));
331+ auto p = p_;
332+ auto len = sizeof (T);
333+ auto offset = offset_;
334+ while (len > 0 ) {
335+ auto remainder = std::min (p->Length () - offset, len);
336+ auto data = p->Data () + offset;
337+ chunk.insert (chunk.end (), data, data + remainder);
338+ p = p->Next ();
339+ offset = 0 ;
340+ len -= remainder;
341+ }
342+ return *reinterpret_cast <T*>(Data ());
343+ }
344+ #else
345+
323346 if (p_->Length () - offset_ < sizeof (T)) {
324347 throw std::runtime_error (
325348 " MutDataPointer::Get(): request straddles buffer" );
326349 }
327-
350+ # endif
328351 return *reinterpret_cast <T*>(Data ());
329352 }
330353
@@ -355,6 +378,7 @@ class MutIOBuf : public IOBuf {
355378 private:
356379 MutIOBuf* p_{nullptr };
357380 size_t offset_{0 };
381+ std::forward_list<std::vector<char >> chunk_list;
358382 };
359383
360384 MutDataPointer GetMutDataPointer () { return MutDataPointer (this ); }
You can’t perform that action at this time.
0 commit comments