mirror of
https://github.com/facebookincubator/mvfst.git
synced 2025-04-18 17:24:03 +03:00
Reviewed By: lnicco Differential Revision: D33587012 fbshipit-source-id: 972eb440f0156c9c04aa6e8787561b18295c1a97
34 lines
913 B
C++
34 lines
913 B
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <quic/common/BufAccessor.h>
|
|
|
|
namespace quic {
|
|
SimpleBufAccessor::SimpleBufAccessor(size_t capacity)
|
|
: buf_(folly::IOBuf::create(capacity)), capacity_(buf_->capacity()) {}
|
|
|
|
Buf SimpleBufAccessor::obtain() {
|
|
Buf ret;
|
|
buf_.swap(ret);
|
|
return ret;
|
|
}
|
|
|
|
void SimpleBufAccessor::release(Buf buf) {
|
|
CHECK(!buf_) << "Can't override existing buf";
|
|
CHECK(buf) << "Invalid Buf being released";
|
|
CHECK_EQ(buf->capacity(), capacity_)
|
|
<< "Buf has wrong capacity, capacit_=" << capacity_
|
|
<< ", buf capacity=" << buf->capacity();
|
|
CHECK(!buf->isChained()) << "Reject chained buf";
|
|
buf_ = std::move(buf);
|
|
}
|
|
|
|
bool SimpleBufAccessor::ownsBuffer() const {
|
|
return (buf_ != nullptr);
|
|
}
|
|
} // namespace quic
|