ClickHouse/dbms/include/DB/IO/WriteBufferFromFileDescriptor.h

54 lines
955 B
C++
Raw Normal View History

2011-10-24 12:10:59 +00:00
#pragma once
#include <DB/IO/WriteBufferFromFileBase.h>
2011-10-24 12:10:59 +00:00
namespace DB
{
/** Use ready file descriptor. Does not open or close a file.
2011-10-24 12:10:59 +00:00
*/
class WriteBufferFromFileDescriptor : public WriteBufferFromFileBase
2011-10-24 12:10:59 +00:00
{
protected:
int fd;
2016-10-25 06:49:24 +00:00
void nextImpl() override;
2011-10-24 12:10:59 +00:00
/// Name or some description of file.
2016-10-25 06:49:24 +00:00
std::string getFileName() const override;
2011-10-24 12:10:59 +00:00
public:
2016-10-25 06:49:24 +00:00
WriteBufferFromFileDescriptor(
int fd_ = -1,
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE,
char * existing_memory = nullptr,
size_t alignment = 0);
2011-10-24 12:10:59 +00:00
/** Could be used before initialization if needed 'fd' was not passed to constructor.
* It's not possible to change 'fd' during work.
*/
void setFD(int fd_)
{
fd = fd_;
}
2017-03-09 04:26:17 +00:00
~WriteBufferFromFileDescriptor() override;
int getFD() const override
{
return fd;
}
2016-10-25 06:49:24 +00:00
off_t getPositionInFile() override;
2016-10-25 06:49:24 +00:00
void sync() override;
private:
2016-10-25 06:49:24 +00:00
off_t doSeek(off_t offset, int whence) override;
2016-10-25 06:49:24 +00:00
void doTruncate(off_t length) override;
2011-10-24 12:10:59 +00:00
};
}