ClickHouse/dbms/IO/WriteBufferFromFileDescriptor.h

50 lines
963 B
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
{
return fd;
}
void sync() override;
off_t seek(off_t offset, int whence);
void truncate(off_t length);
2011-10-24 12:10:59 +00:00
};
}