2011-10-24 12:10:59 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <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:
|
2017-04-01 07:20:54 +00:00
|
|
|
int fd;
|
2015-04-16 12:06:05 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void nextImpl() override;
|
2011-10-24 12:10:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Name or some description of file.
|
|
|
|
std::string getFileName() const override;
|
2011-10-24 12:10:59 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +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
|
|
|
|
2017-04-01 07:20:54 +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_;
|
|
|
|
}
|
2012-02-24 19:21:38 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
~WriteBufferFromFileDescriptor() override;
|
2011-12-28 20:01:41 +00:00
|
|
|
|
2020-02-20 16:39:32 +00:00
|
|
|
int getFD() const
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
return fd;
|
|
|
|
}
|
2011-12-28 20:01:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void sync() override;
|
2015-04-03 13:45:44 +00:00
|
|
|
|
2020-02-20 16:39:32 +00:00
|
|
|
off_t seek(off_t offset, int whence);
|
|
|
|
void truncate(off_t length);
|
2011-10-24 12:10:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|