ClickHouse/dbms/IO/MMapReadBufferFromFileDescriptor.h

46 lines
1.1 KiB
C++
Raw Normal View History

2018-06-13 02:52:03 +00:00
#pragma once
#include <IO/ReadBufferFromFileBase.h>
2018-06-13 02:52:03 +00:00
namespace DB
{
/** MMap range in a file and represent it as a ReadBuffer.
* Please note that mmap is not always the optimal way to read file.
* Also you cannot control whether and how long actual IO take place,
* so this method is not manageable and not recommended for anything except benchmarks.
*/
class MMapReadBufferFromFileDescriptor : public ReadBufferFromFileBase
2018-06-13 02:52:03 +00:00
{
public:
off_t seek(off_t off, int whence) override;
2018-06-13 02:52:03 +00:00
protected:
MMapReadBufferFromFileDescriptor() {}
2018-06-13 02:52:03 +00:00
void init(int fd_, size_t offset, size_t length_);
void init(int fd_, size_t offset);
public:
2019-08-03 11:02:40 +00:00
MMapReadBufferFromFileDescriptor(int fd_, size_t offset_, size_t length_);
2018-06-13 02:52:03 +00:00
/// Map till end of file.
2019-08-03 11:02:40 +00:00
MMapReadBufferFromFileDescriptor(int fd_, size_t offset_);
2018-06-13 02:52:03 +00:00
~MMapReadBufferFromFileDescriptor() override;
/// unmap memory before call to destructor
void finish();
2020-02-14 14:28:33 +00:00
off_t getPosition() override;
std::string getFileName() const override;
2020-02-14 14:28:33 +00:00
int getFD() const;
2018-06-13 02:52:03 +00:00
private:
size_t length = 0;
int fd = -1;
};
}