blob: 10c36d9e1d38237e93c67ac163448e453f3a8e8f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#pragma once
#include <Common/CurrentMetrics.h>
#include <memory>
#include <mutex>
namespace CurrentMetrics
{
extern const Metric OpenFileForRead;
}
namespace DB
{
/// RAII for readonly opened file descriptor.
class OpenedFile
{
public:
OpenedFile(const std::string & file_name_, int flags_);
~OpenedFile();
/// Close prematurally.
void close();
int getFD() const;
std::string getFileName() const;
private:
std::string file_name;
int flags = 0;
mutable int fd = -1;
mutable std::mutex mutex;
CurrentMetrics::Increment metric_increment{CurrentMetrics::OpenFileForRead};
void open() const;
};
}
|