2 * Copyright (c) 2015, Facebook, Inc.
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.
14 class IConnectionCounter {
16 virtual uint64_t getNumConnections() const = 0;
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."
23 virtual uint64_t getMaxConnections() const = 0;
26 * Increment the count of client-side connections.
28 virtual void onConnectionAdded() = 0;
31 * Decrement the count of client-side connections.
33 virtual void onConnectionRemoved() = 0;
34 virtual ~IConnectionCounter() {}
37 class SimpleConnectionCounter: public IConnectionCounter {
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;
45 void onConnectionAdded() override { numConnections_++; }
46 void onConnectionRemoved() override { numConnections_--; }
47 virtual ~SimpleConnectionCounter() {}
50 uint64_t maxConnections_{0};
51 uint64_t numConnections_{0};