Get *=default*ed default constructors
[folly.git] / folly / wangle / acceptor / ConnectionCounter.h
1 /*
2  *  Copyright (c) 2015, Facebook, Inc.
3  *  All rights reserved.
4  *
5  *  This source code is licensed under the BSD-style license found in the
6  *  LICENSE file in the root directory of this source tree. An additional grant
7  *  of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11
12 namespace folly {
13
14 class IConnectionCounter {
15  public:
16   virtual uint64_t getNumConnections() const = 0;
17
18   /**
19    * Get the maximum number of non-whitelisted client-side connections
20    * across all Acceptors managed by this. A value
21    * of zero means "unlimited."
22    */
23   virtual uint64_t getMaxConnections() const = 0;
24
25   /**
26    * Increment the count of client-side connections.
27    */
28   virtual void onConnectionAdded() = 0;
29
30   /**
31    * Decrement the count of client-side connections.
32    */
33   virtual void onConnectionRemoved() = 0;
34   virtual ~IConnectionCounter() = default;
35 };
36
37 class SimpleConnectionCounter: public IConnectionCounter {
38  public:
39   uint64_t getNumConnections() const override { return numConnections_; }
40   uint64_t getMaxConnections() const override { return maxConnections_; }
41   void setMaxConnections(uint64_t maxConnections) {
42     maxConnections_ = maxConnections;
43   }
44
45   void onConnectionAdded() override { numConnections_++; }
46   void onConnectionRemoved() override { numConnections_--; }
47   virtual ~SimpleConnectionCounter() = default;
48
49  protected:
50   uint64_t maxConnections_{0};
51   uint64_t numConnections_{0};
52 };
53
54 }