proxygen
SocketOptions.cpp
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  */
17 
19 
20 using folly::AsyncSocket;
21 
22 namespace wangle {
23 
25  const AsyncSocket::OptionMap& allOptions,
26  const int addrFamily) {
28  int exclude;
29  if (addrFamily == AF_INET) {
30  exclude = IPPROTO_IPV6;
31  } else if (addrFamily == AF_INET6) {
32  exclude = IPPROTO_IP;
33  } else {
34  LOG(FATAL) << "Address family " << addrFamily << " was not IPv4 or IPv6";
35  }
36  for (const auto& opt: allOptions) {
37  if (opt.first.level != exclude) {
38  opts[opt.first] = opt.second;
39  }
40  }
41  return opts;
42 }
43 
44 } // namespace wangle
std::map< OptionKey, int > OptionMap
Definition: AsyncSocket.h:376
AsyncSocket::OptionMap filterIPSocketOptions(const AsyncSocket::OptionMap &allOptions, const int addrFamily)