Apache Mesos
pipe.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 #ifndef __STOUT_OS_WINDOWS_PIPE_HPP__
14 #define __STOUT_OS_WINDOWS_PIPE_HPP__
15 
16 #include <array>
17 
18 #include <stout/error.hpp>
19 #include <stout/try.hpp>
20 
21 namespace os {
22 
23 // Create pipes for interprocess communication. Since the pipes cannot
24 // be used directly by Posix `read/write' functions they are wrapped
25 // in file descriptors, a process-local concept.
27 {
28  // Create inheritable pipe, as described in MSDN[1].
29  //
30  // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365782(v=vs.85).aspx
31  SECURITY_ATTRIBUTES securityAttr;
32  securityAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
33  securityAttr.bInheritHandle = TRUE;
34  securityAttr.lpSecurityDescriptor = nullptr;
35 
36  HANDLE read_handle;
37  HANDLE write_handle;
38 
39  const BOOL result =
40  ::CreatePipe(&read_handle, &write_handle, &securityAttr, 0);
41 
42  if (!result) {
43  return WindowsError();
44  }
45 
46  return std::array<WindowsFD, 2>{read_handle, write_handle};
47 }
48 
49 } // namespace os {
50 
51 #endif // __STOUT_OS_WINDOWS_PIPE_HPP__
Definition: check.hpp:33
Definition: error.hpp:106
Definition: posix_signalhandler.hpp:23
constexpr Handle HANDLE
Definition: ingress.hpp:37
Try< std::array< int, 2 > > pipe()
Definition: pipe.hpp:26