1
#pragma once
2

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

            
6
#include "envoy/common/time.h"
7

            
8
#include "source/common/common/logger.h"
9
#include "source/common/common/thread.h"
10
#include "source/common/common/token_bucket_impl.h"
11
#include "source/common/network/address_impl.h"
12

            
13
#include "absl/base/thread_annotations.h"
14
#include "absl/strings/string_view.h"
15

            
16
namespace Envoy {
17
namespace Cilium {
18

            
19
class UDSClient : Logger::Loggable<Logger::Id::router> {
20
public:
21
  UDSClient(const std::string& path, TimeSource& time_source);
22
  ~UDSClient();
23

            
24
  void log(const std::string& msg);
25

            
26
  const std::string& asString() const { return addr_->asString(); }
27
  absl::string_view asStringView() const { return addr_->asStringView(); }
28

            
29
private:
30
  bool tryConnect() ABSL_EXCLUSIVE_LOCKS_REQUIRED(fd_mutex_);
31

            
32
  Thread::MutexBasicLockable fd_mutex_;
33
  std::shared_ptr<Network::Address::PipeInstance> addr_;
34
  int fd_ ABSL_GUARDED_BY(fd_mutex_);
35
  int errno_ ABSL_GUARDED_BY(fd_mutex_);
36
  std::unique_ptr<TokenBucketImpl> logging_limiter_ ABSL_GUARDED_BY(fd_mutex_);
37
};
38

            
39
} // namespace Cilium
40
} // namespace Envoy