proxygen
NetworkAddress.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <folly/SocketAddress.h>
19 
20 namespace wangle {
21 
27 public:
34  unsigned prefixLen):
35  addr_(addr), prefixLen_(prefixLen) {}
36 
39  return addr_;
40  }
41 
43  unsigned getPrefixLength() const { return prefixLen_; }
44 
46  bool contains(const folly::SocketAddress& addr) const {
47  return addr_.prefixMatch(addr, prefixLen_);
48  }
49 
51  bool operator<(const NetworkAddress& other) const {
52  if (addr_ < other.addr_) {
53  return true;
54  } else if (other.addr_ < addr_) {
55  return false;
56  } else {
57  return (prefixLen_ < other.prefixLen_);
58  }
59  }
60 
61  bool operator==(const NetworkAddress& other) const {
62  return addr_ == other.addr_ && prefixLen_ == other.prefixLen_;
63  }
64 
65 private:
67  unsigned prefixLen_;
68 };
69 
70 } // namespace wangle
bool prefixMatch(const SocketAddress &other, unsigned prefixLength) const
unsigned getPrefixLength() const
folly::SocketAddress addr_
bool contains(const folly::SocketAddress &addr) const
bool operator==(const NetworkAddress &other) const
NetworkAddress(const folly::SocketAddress &addr, unsigned prefixLen)
ThreadPoolListHook * addr
const folly::SocketAddress & getAddress() const
bool operator<(const NetworkAddress &other) const