proxygen
SocketPair.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-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 
18 
19 #include <folly/Conv.h>
23 
24 #include <errno.h>
25 #include <stdexcept>
26 
27 namespace folly {
28 
30  if (socketpair(PF_UNIX, SOCK_STREAM, 0, fds_) != 0) {
31  throw std::runtime_error(folly::to<std::string>(
32  "test::SocketPair: failed create socket pair", errno));
33  }
34 
35  if (mode == NONBLOCKING) {
36  if (fcntl(fds_[0], F_SETFL, O_NONBLOCK) != 0) {
37  throw std::runtime_error(folly::to<std::string>(
38  "test::SocketPair: failed to set non-blocking "
39  "read mode",
40  errno));
41  }
42  if (fcntl(fds_[1], F_SETFL, O_NONBLOCK) != 0) {
43  throw std::runtime_error(folly::to<std::string>(
44  "test::SocketPair: failed to set non-blocking "
45  "write mode",
46  errno));
47  }
48  }
49 }
50 
52  closeFD0();
53  closeFD1();
54 }
55 
57  if (fds_[0] >= 0) {
58  close(fds_[0]);
59  fds_[0] = -1;
60  }
61 }
62 
64  if (fds_[1] >= 0) {
65  close(fds_[1]);
66  fds_[1] = -1;
67  }
68 }
69 
70 } // namespace folly
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
folly::Optional< PskKeyExchangeMode > mode
int close(NetworkSocket s)
Definition: NetOps.cpp:90
int socketpair(int domain, int type, int protocol, NetworkSocket sv[2])
Definition: NetOps.cpp:416
SocketPair(Mode mode=NONBLOCKING)
Definition: SocketPair.cpp:29