ClickHouse/dbms/src/IO/WriteBufferFromFileDescriptor.h

54 lines
1.0 KiB
C++
Raw Normal View History

2011-10-24 12:10:59 +00:00
#pragma once
#include <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;
void nextImpl() override;
2011-10-24 12:10:59 +00:00
/// Name or some description of file.
std::string getFileName() const override;
2011-10-24 12:10:59 +00:00
public:
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_;
}
~WriteBufferFromFileDescriptor() override;
int getFD() const override
{
return fd;
}
off_t getPositionInFile() override;
void sync() override;
private:
off_t doSeek(off_t offset, int whence) override;
void doTruncate(off_t length) override;
2011-10-24 12:10:59 +00:00
};
}