Adds writer test case for RCU
[folly.git] / folly / io / async / test / SocketPair.h
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
17 #pragma once
18
19 namespace folly {
20
21 class SocketPair {
22  public:
23   enum Mode {
24     BLOCKING,
25     NONBLOCKING
26   };
27
28   explicit SocketPair(Mode mode = NONBLOCKING);
29   ~SocketPair();
30
31   int operator[](int index) const {
32     return fds_[index];
33   }
34
35   void closeFD0();
36   void closeFD1();
37
38   int extractFD0() {
39     return extractFD(0);
40   }
41   int extractFD1() {
42     return extractFD(1);
43   }
44   int extractFD(int index) {
45     int fd = fds_[index];
46     fds_[index] = -1;
47     return fd;
48   }
49
50  private:
51   int fds_[2];
52 };
53
54 } // namespace folly