2011-10-24 12:10:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-03-30 15:39:55 +00:00
|
|
|
#include <DB/IO/WriteBufferFromFileBase.h>
|
2016-10-24 02:02:37 +00:00
|
|
|
|
2016-10-24 04:06:27 +00:00
|
|
|
|
2011-10-24 12:10:59 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/** Use ready file descriptor. Does not open or close a file.
|
2011-10-24 12:10:59 +00:00
|
|
|
*/
|
2015-03-30 15:39:55 +00:00
|
|
|
class WriteBufferFromFileDescriptor : public WriteBufferFromFileBase
|
2011-10-24 12:10:59 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
int fd;
|
2015-04-16 12:06:05 +00:00
|
|
|
|
2016-10-25 06:49:24 +00:00
|
|
|
void nextImpl() override;
|
2011-10-24 12:10:59 +00:00
|
|
|
|
2016-10-24 02:02:37 +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
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/** Could be used before initialization if needed 'fd' was not passed to constructor.
|
|
|
|
* It's not possible to change 'fd' during work.
|
2012-02-24 19:21:38 +00:00
|
|
|
*/
|
|
|
|
void setFD(int fd_)
|
|
|
|
{
|
|
|
|
fd = fd_;
|
|
|
|
}
|
|
|
|
|
2016-10-25 06:49:24 +00:00
|
|
|
~WriteBufferFromFileDescriptor() override;
|
2011-12-28 20:01:41 +00:00
|
|
|
|
2015-04-14 11:35:10 +00:00
|
|
|
int getFD() const override
|
2011-12-28 20:01:41 +00:00
|
|
|
{
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2016-10-25 06:49:24 +00:00
|
|
|
off_t getPositionInFile() override;
|
2015-03-30 15:39:55 +00:00
|
|
|
|
2016-10-25 06:49:24 +00:00
|
|
|
void sync() override;
|
2015-04-03 13:45:44 +00:00
|
|
|
|
|
|
|
private:
|
2016-10-25 06:49:24 +00:00
|
|
|
off_t doSeek(off_t offset, int whence) override;
|
2015-04-30 15:04:42 +00:00
|
|
|
|
2016-10-25 06:49:24 +00:00
|
|
|
void doTruncate(off_t length) override;
|
2011-10-24 12:10:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|