sapling/eden/fs/fuse/BufVec.h
Adam Simpkins bfcf4c574a remove the fusell namespace
Summary: Move everything in the `facebook::eden::fusell` namespace to `facebook::eden`

Reviewed By: chadaustin

Differential Revision: D7314458

fbshipit-source-id: db56d3e5fb898235e1376ac76077cf780d9b4698
2018-03-19 17:01:52 -07:00

68 lines
1.7 KiB
C++

/*
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#pragma once
#include <folly/FBVector.h>
#include <folly/io/IOBuf.h>
namespace facebook {
namespace eden {
/**
* Represents data that may come from a buffer or a file descriptor.
*
* While we don't currently have a fuse client lib that supports this,
* we want to make sure we're ready to use it, so this looks like
* a dumb wrapper around IOBuf at the moment.
*/
class BufVec {
struct Buf {
std::unique_ptr<folly::IOBuf> buf;
int fd{-1};
size_t fd_size{0};
off_t fd_pos{-1};
Buf(const Buf&) = delete;
Buf& operator=(const Buf&) = delete;
Buf(Buf&&) = default;
Buf& operator=(Buf&&) = default;
explicit Buf(std::unique_ptr<folly::IOBuf> buf);
};
folly::fbvector<std::shared_ptr<Buf>> items_;
public:
BufVec(const BufVec&) = delete;
BufVec& operator=(const BufVec&) = delete;
BufVec(BufVec&&) = default;
BufVec& operator=(BufVec&&) = default;
explicit BufVec(std::unique_ptr<folly::IOBuf> buf);
/**
* Return an iovector suitable for e.g. writev()
* auto iov = buf->getIov();
* auto xfer = writev(fd, iov.data(), iov.size());
*/
folly::fbvector<struct iovec> getIov() const;
/**
* Returns the total number of bytes in the BufVec.
*/
size_t size() const;
/**
* Copies the buffer into a std::string.
*/
std::string copyData() const;
};
} // namespace eden
} // namespace facebook