1
#pragma once
2

            
3
#include <cstdint>
4

            
5
#include "envoy/event/file_event.h"
6

            
7
#include "source/common/event/dispatcher_impl.h"
8
#include "source/common/event/event_impl_base.h"
9

            
10
namespace Envoy {
11
namespace Event {
12

            
13
/**
14
 * Implementation of FileEvent for libevent that uses persistent events and
15
 * assumes the user will read/write until EAGAIN is returned from the file.
16
 */
17
class FileEventImpl : public FileEvent, ImplBase {
18
public:
19
  FileEventImpl(DispatcherImpl& dispatcher, os_fd_t fd, FileReadyCb cb, FileTriggerType trigger,
20
                uint32_t events);
21

            
22
  // Event::FileEvent
23
  void activate(uint32_t events) override;
24
  void setEnabled(uint32_t events) override;
25
  void unregisterEventIfEmulatedEdge(uint32_t event) override;
26
  void registerEventIfEmulatedEdge(uint32_t event) override;
27

            
28
private:
29
  void assignEvents(uint32_t events, event_base* base);
30
  void mergeInjectedEventsAndRunCb(uint32_t events);
31
  void updateEvents(uint32_t events);
32

            
33
  Dispatcher& dispatcher_;
34
  FileReadyCb cb_;
35
  os_fd_t fd_;
36
  FileTriggerType trigger_;
37
  // Enabled events for this fd.
38
  uint32_t enabled_events_;
39

            
40
  // Injected FileReadyType events that were scheduled by recent calls to activate() and are pending
41
  // delivery.
42
  uint32_t injected_activation_events_{};
43
  // Used to schedule delayed event activation. Armed iff pending_activation_events_ != 0.
44
  SchedulableCallbackPtr activation_cb_;
45
};
46
} // namespace Event
47
} // namespace Envoy