1
#pragma once
2

            
3
#include <memory>
4
#include <string>
5

            
6
#include "source/common/buffer/buffer_impl.h"
7
#include "source/extensions/common/async_files/async_file_context_base.h"
8

            
9
#include "absl/status/statusor.h"
10

            
11
namespace Envoy {
12
namespace Extensions {
13
namespace Common {
14
namespace AsyncFiles {
15

            
16
class AsyncFileManager;
17

            
18
// The thread pool implementation of an AsyncFileContext - uses the manager thread pool and
19
// old-school synchronous posix file operations.
20
class AsyncFileContextThreadPool final : public AsyncFileContextBase {
21
public:
22
  explicit AsyncFileContextThreadPool(AsyncFileManager& manager, int fd);
23

            
24
  // CancelFunction should not be called during or after the callback.
25
  // CancelFunction should only be called from the same thread that created
26
  // the context.
27
  // The callback will be dispatched to the same thread that created the context.
28
  absl::StatusOr<CancelFunction>
29
  stat(Event::Dispatcher* dispatcher,
30
       absl::AnyInvocable<void(absl::StatusOr<struct stat>)> on_complete) override;
31
  absl::StatusOr<CancelFunction>
32
  createHardLink(Event::Dispatcher* dispatcher, absl::string_view filename,
33
                 absl::AnyInvocable<void(absl::Status)> on_complete) override;
34
  absl::StatusOr<CancelFunction> close(Event::Dispatcher* dispatcher,
35
                                       absl::AnyInvocable<void(absl::Status)> on_complete) override;
36
  absl::StatusOr<CancelFunction>
37
  read(Event::Dispatcher* dispatcher, off_t offset, size_t length,
38
       absl::AnyInvocable<void(absl::StatusOr<Buffer::InstancePtr>)> on_complete) override;
39
  absl::StatusOr<CancelFunction>
40
  write(Event::Dispatcher* dispatcher, Buffer::Instance& contents, off_t offset,
41
        absl::AnyInvocable<void(absl::StatusOr<size_t>)> on_complete) override;
42
  absl::StatusOr<CancelFunction>
43
  duplicate(Event::Dispatcher* dispatcher,
44
            absl::AnyInvocable<void(absl::StatusOr<AsyncFileHandle>)> on_complete) override;
45
  absl::StatusOr<CancelFunction>
46
  truncate(Event::Dispatcher* dispatcher, size_t length,
47
           absl::AnyInvocable<void(absl::Status)> on_complete) override;
48

            
49
8028
  int& fileDescriptor() { return file_descriptor_; }
50

            
51
  ~AsyncFileContextThreadPool() override;
52

            
53
protected:
54
  absl::StatusOr<CancelFunction> checkFileAndEnqueue(Event::Dispatcher* dispatcher,
55
                                                     std::unique_ptr<AsyncFileAction> action);
56

            
57
  int file_descriptor_;
58
};
59

            
60
} // namespace AsyncFiles
61
} // namespace Common
62
} // namespace Extensions
63
} // namespace Envoy