proxygen
folly::gen::detail::FileReader Class Reference

#include <File-inl.h>

Inheritance diagram for folly::gen::detail::FileReader:
folly::gen::GenImpl< ByteRange, FileReader > folly::gen::FBounded< Self >

Public Member Functions

 FileReader (File file, std::unique_ptr< IOBuf > buffer)
 
template<class Body >
bool apply (Body &&body) const
 
- Public Member Functions inherited from folly::gen::GenImpl< ByteRange, FileReader >
bool apply (Handler &&handler) const
 
void foreach (Body &&body) const
 
- Public Member Functions inherited from folly::gen::FBounded< Self >
const Self & self () const
 
Self & self ()
 

Static Public Attributes

static constexpr bool infinite = false
 
- Static Public Attributes inherited from folly::gen::GenImpl< ByteRange, FileReader >
static constexpr bool infinite
 

Private Attributes

File file_
 
std::unique_ptr< IOBufbuffer_
 

Additional Inherited Members

- Public Types inherited from folly::gen::GenImpl< ByteRange, FileReader >
typedef ByteRange ValueType
 
typedef std::decay< ByteRange >::type StorageType
 
- Protected Member Functions inherited from folly::gen::GenImpl< ByteRange, FileReader >
 GenImpl ()=default
 
 GenImpl (GenImpl &&)=default
 
 GenImpl (const GenImpl &)=default
 
GenImploperator= (GenImpl &&)=default
 
GenImploperator= (const GenImpl &)=default
 

Detailed Description

Definition at line 29 of file File-inl.h.

Constructor & Destructor Documentation

folly::gen::detail::FileReader::FileReader ( File  file,
std::unique_ptr< IOBuf buffer 
)
inline

Definition at line 31 of file File-inl.h.

References buffer_.

32  : file_(std::move(file)), buffer_(std::move(buffer)) {
33  buffer_->clear();
34  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< IOBuf > buffer_
Definition: File-inl.h:61

Member Function Documentation

template<class Body >
bool folly::gen::detail::FileReader::apply ( Body &&  body) const
inline

Definition at line 37 of file File-inl.h.

References buffer_, folly::File::fd(), file_, and fizz::detail::read().

37  {
38  for (;;) {
39  ssize_t n;
40  do {
41  n = ::read(file_.fd(), buffer_->writableTail(), buffer_->capacity());
42  } while (n == -1 && errno == EINTR);
43  if (n == -1) {
44  throw std::system_error(errno, std::system_category(), "read failed");
45  }
46  if (n == 0) {
47  return true;
48  }
49  if (!body(ByteRange(buffer_->tail(), size_t(n)))) {
50  return false;
51  }
52  }
53  }
std::unique_ptr< IOBuf > buffer_
Definition: File-inl.h:61
int fd() const
Definition: File.h:85
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
Range< const unsigned char * > ByteRange
Definition: Range.h:1163

Member Data Documentation

std::unique_ptr<IOBuf> folly::gen::detail::FileReader::buffer_
private
File folly::gen::detail::FileReader::file_
private
constexpr bool folly::gen::detail::FileReader::infinite = false
static

Definition at line 57 of file File-inl.h.


The documentation for this class was generated from the following file: