1 // pipes.hpp --------------------------------------------------------------//
3 // Copyright 2016 Klemens D. Morgenstern
4 // Copyright 2016 Andrey Semashev
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
9 #ifndef BOOST_DETAIL_WINAPI_PIPES_HPP_
10 #define BOOST_DETAIL_WINAPI_PIPES_HPP_
12 #include <boost/detail/winapi/basic_types.hpp>
13 #include <boost/detail/winapi/config.hpp>
14 #include <boost/detail/winapi/overlapped.hpp>
15 #include <boost/predef/platform.h>
17 #ifdef BOOST_HAS_PRAGMA_ONCE
21 #if BOOST_PLAT_WINDOWS_DESKTOP
23 #if !defined( BOOST_USE_WINDOWS_H )
26 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI ImpersonateNamedPipeClient(
27 boost::detail::winapi::HANDLE_ hNamedPipe);
29 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI CreatePipe(
30 boost::detail::winapi::PHANDLE_ hReadPipe,
31 boost::detail::winapi::PHANDLE_ hWritePipe,
32 _SECURITY_ATTRIBUTES* lpPipeAttributes,
33 boost::detail::winapi::DWORD_ nSize);
35 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI ConnectNamedPipe(
36 boost::detail::winapi::HANDLE_ hNamedPipe,
37 _OVERLAPPED* lpOverlapped);
39 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI DisconnectNamedPipe(
40 boost::detail::winapi::HANDLE_ hNamedPipe);
42 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI SetNamedPipeHandleState(
43 boost::detail::winapi::HANDLE_ hNamedPipe,
44 boost::detail::winapi::LPDWORD_ lpMode,
45 boost::detail::winapi::LPDWORD_ lpMaxCollectionCount,
46 boost::detail::winapi::LPDWORD_ lpCollectDataTimeout);
48 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI PeekNamedPipe(
49 boost::detail::winapi::HANDLE_ hNamedPipe,
50 boost::detail::winapi::LPVOID_ lpBuffer,
51 boost::detail::winapi::DWORD_ nBufferSize,
52 boost::detail::winapi::LPDWORD_ lpBytesRead,
53 boost::detail::winapi::LPDWORD_ lpTotalBytesAvail,
54 boost::detail::winapi::LPDWORD_ lpBytesLeftThisMessage);
56 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI TransactNamedPipe(
57 boost::detail::winapi::HANDLE_ hNamedPipe,
58 boost::detail::winapi::LPVOID_ lpInBuffer,
59 boost::detail::winapi::DWORD_ nInBufferSize,
60 boost::detail::winapi::LPVOID_ lpOutBuffer,
61 boost::detail::winapi::DWORD_ nOutBufferSize,
62 boost::detail::winapi::LPDWORD_ lpBytesRead,
63 _OVERLAPPED* lpOverlapped);
65 #if !defined( BOOST_NO_ANSI_APIS )
66 BOOST_SYMBOL_IMPORT boost::detail::winapi::HANDLE_ WINAPI CreateNamedPipeA(
67 boost::detail::winapi::LPCSTR_ lpName,
68 boost::detail::winapi::DWORD_ dwOpenMode,
69 boost::detail::winapi::DWORD_ dwPipeMode,
70 boost::detail::winapi::DWORD_ nMaxInstances,
71 boost::detail::winapi::DWORD_ nOutBufferSize,
72 boost::detail::winapi::DWORD_ nInBufferSize,
73 boost::detail::winapi::DWORD_ nDefaultTimeOut,
74 _SECURITY_ATTRIBUTES *lpSecurityAttributes);
76 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI WaitNamedPipeA(
77 boost::detail::winapi::LPCSTR_ lpNamedPipeName,
78 boost::detail::winapi::DWORD_ nTimeOut);
79 #endif // !defined( BOOST_NO_ANSI_APIS )
81 BOOST_SYMBOL_IMPORT boost::detail::winapi::HANDLE_ WINAPI CreateNamedPipeW(
82 boost::detail::winapi::LPCWSTR_ lpName,
83 boost::detail::winapi::DWORD_ dwOpenMode,
84 boost::detail::winapi::DWORD_ dwPipeMode,
85 boost::detail::winapi::DWORD_ nMaxInstances,
86 boost::detail::winapi::DWORD_ nOutBufferSize,
87 boost::detail::winapi::DWORD_ nInBufferSize,
88 boost::detail::winapi::DWORD_ nDefaultTimeOut,
89 _SECURITY_ATTRIBUTES* lpSecurityAttributes);
91 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI WaitNamedPipeW(
92 boost::detail::winapi::LPCWSTR_ lpNamedPipeName,
93 boost::detail::winapi::DWORD_ nTimeOut);
95 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
96 #if !defined( BOOST_NO_ANSI_APIS )
97 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI GetNamedPipeClientComputerNameA(
98 boost::detail::winapi::HANDLE_ Pipe,
99 boost::detail::winapi::LPSTR_ ClientComputerName,
100 boost::detail::winapi::ULONG_ ClientComputerNameLength);
101 #endif // !defined( BOOST_NO_ANSI_APIS )
103 BOOST_SYMBOL_IMPORT boost::detail::winapi::BOOL_ WINAPI GetNamedPipeClientComputerNameW(
104 boost::detail::winapi::HANDLE_ Pipe,
105 boost::detail::winapi::LPWSTR_ ClientComputerName,
106 boost::detail::winapi::ULONG_ ClientComputerNameLength);
110 #endif // !defined( BOOST_USE_WINDOWS_H )
116 #if defined( BOOST_USE_WINDOWS_H )
118 const DWORD_ PIPE_ACCESS_DUPLEX_ = PIPE_ACCESS_DUPLEX;
119 const DWORD_ PIPE_ACCESS_INBOUND_ = PIPE_ACCESS_INBOUND;
120 const DWORD_ PIPE_ACCESS_OUTBOUND_ = PIPE_ACCESS_OUTBOUND;
122 const DWORD_ PIPE_TYPE_BYTE_ = PIPE_TYPE_BYTE;
123 const DWORD_ PIPE_TYPE_MESSAGE_ = PIPE_TYPE_MESSAGE;
125 const DWORD_ PIPE_READMODE_BYTE_ = PIPE_READMODE_BYTE;
126 const DWORD_ PIPE_READMODE_MESSAGE_ = PIPE_READMODE_MESSAGE;
128 const DWORD_ PIPE_WAIT_ = PIPE_WAIT;
129 const DWORD_ PIPE_NOWAIT_ = PIPE_NOWAIT;
131 const DWORD_ PIPE_UNLIMITED_INSTANCES_ = PIPE_UNLIMITED_INSTANCES;
133 const DWORD_ NMPWAIT_USE_DEFAULT_WAIT_ = NMPWAIT_USE_DEFAULT_WAIT;
134 const DWORD_ NMPWAIT_NOWAIT_ = NMPWAIT_NOWAIT;
135 const DWORD_ NMPWAIT_WAIT_FOREVER_ = NMPWAIT_WAIT_FOREVER;
137 #else // defined( BOOST_USE_WINDOWS_H )
139 const DWORD_ PIPE_ACCESS_DUPLEX_ = 0x00000003;
140 const DWORD_ PIPE_ACCESS_INBOUND_ = 0x00000001;
141 const DWORD_ PIPE_ACCESS_OUTBOUND_ = 0x00000002;
143 const DWORD_ PIPE_TYPE_BYTE_ = 0x00000000;
144 const DWORD_ PIPE_TYPE_MESSAGE_ = 0x00000004;
146 const DWORD_ PIPE_READMODE_BYTE_ = 0x00000000;
147 const DWORD_ PIPE_READMODE_MESSAGE_ = 0x00000002;
149 const DWORD_ PIPE_WAIT_ = 0x00000000;
150 const DWORD_ PIPE_NOWAIT_ = 0x00000001;
152 const DWORD_ PIPE_UNLIMITED_INSTANCES_ = 255u;
154 const DWORD_ NMPWAIT_USE_DEFAULT_WAIT_ = 0x00000000;
155 const DWORD_ NMPWAIT_NOWAIT_ = 0x00000001;
156 const DWORD_ NMPWAIT_WAIT_FOREVER_ = 0xFFFFFFFF;
158 #endif // defined( BOOST_USE_WINDOWS_H )
160 // These constants are not defined in Windows SDK prior to 7.0A
161 const DWORD_ PIPE_ACCEPT_REMOTE_CLIENTS_ = 0x00000000;
162 const DWORD_ PIPE_REJECT_REMOTE_CLIENTS_ = 0x00000008;
164 using ::ImpersonateNamedPipeClient;
165 using ::DisconnectNamedPipe;
166 using ::SetNamedPipeHandleState;
167 using ::PeekNamedPipe;
169 #if !defined( BOOST_NO_ANSI_APIS )
170 using ::WaitNamedPipeA;
172 using ::WaitNamedPipeW;
174 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
175 #if !defined( BOOST_NO_ANSI_APIS )
176 using ::GetNamedPipeClientComputerNameA;
177 #endif // !defined( BOOST_NO_ANSI_APIS )
178 using ::GetNamedPipeClientComputerNameW;
179 #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
181 BOOST_FORCEINLINE BOOL_ CreatePipe(PHANDLE_ hReadPipe, PHANDLE_ hWritePipe, LPSECURITY_ATTRIBUTES_ lpPipeAttributes, DWORD_ nSize)
183 return ::CreatePipe(hReadPipe, hWritePipe, reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpPipeAttributes), nSize);
186 BOOST_FORCEINLINE BOOL_ ConnectNamedPipe(HANDLE_ hNamedPipe, LPOVERLAPPED_ lpOverlapped)
188 return ::ConnectNamedPipe(hNamedPipe, reinterpret_cast< ::_OVERLAPPED* >(lpOverlapped));
191 BOOST_FORCEINLINE BOOL_ TransactNamedPipe(HANDLE_ hNamedPipe, LPVOID_ lpInBuffer, DWORD_ nInBufferSize, LPVOID_ lpOutBuffer, DWORD_ nOutBufferSize, LPDWORD_ lpBytesRead, LPOVERLAPPED_ lpOverlapped)
193 return ::TransactNamedPipe(hNamedPipe, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesRead, reinterpret_cast< ::_OVERLAPPED* >(lpOverlapped));
197 #if !defined( BOOST_NO_ANSI_APIS )
198 BOOST_FORCEINLINE HANDLE_ CreateNamedPipeA(
202 DWORD_ nMaxInstances,
203 DWORD_ nOutBufferSize,
204 DWORD_ nInBufferSize,
205 DWORD_ nDefaultTimeOut,
206 LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
208 return ::CreateNamedPipeA(
216 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
219 BOOST_FORCEINLINE HANDLE_ create_named_pipe(
223 DWORD_ nMaxInstances,
224 DWORD_ nOutBufferSize,
225 DWORD_ nInBufferSize,
226 DWORD_ nDefaultTimeOut,
227 LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
229 return ::CreateNamedPipeA(
237 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
239 #endif // !defined( BOOST_NO_ANSI_APIS )
241 BOOST_FORCEINLINE HANDLE_ CreateNamedPipeW(
245 DWORD_ nMaxInstances,
246 DWORD_ nOutBufferSize,
247 DWORD_ nInBufferSize,
248 DWORD_ nDefaultTimeOut,
249 LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
251 return ::CreateNamedPipeW(
259 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
262 BOOST_FORCEINLINE HANDLE_ create_named_pipe(
266 DWORD_ nMaxInstances,
267 DWORD_ nOutBufferSize,
268 DWORD_ nInBufferSize,
269 DWORD_ nDefaultTimeOut,
270 LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
272 return ::CreateNamedPipeW(
280 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
283 #if !defined( BOOST_NO_ANSI_APIS )
284 BOOST_FORCEINLINE BOOL_ wait_named_pipe(LPCSTR_ lpNamedPipeName, DWORD_ nTimeOut)
286 return ::WaitNamedPipeA(lpNamedPipeName, nTimeOut);
288 #endif //BOOST_NO_ANSI_APIS
290 BOOST_FORCEINLINE BOOL_ wait_named_pipe(LPCWSTR_ lpNamedPipeName, DWORD_ nTimeOut)
292 return ::WaitNamedPipeW(lpNamedPipeName, nTimeOut);
295 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
297 #if !defined( BOOST_NO_ANSI_APIS )
298 BOOST_FORCEINLINE BOOL_ get_named_pipe_client_computer_name(HANDLE_ Pipe, LPSTR_ ClientComputerName, ULONG_ ClientComputerNameLength)
300 return ::GetNamedPipeClientComputerNameA(Pipe, ClientComputerName, ClientComputerNameLength);
302 #endif // !defined( BOOST_NO_ANSI_APIS )
304 BOOST_FORCEINLINE BOOL_ get_named_pipe_client_computer_name(HANDLE_ Pipe, LPWSTR_ ClientComputerName, ULONG_ ClientComputerNameLength)
306 return ::GetNamedPipeClientComputerNameW(Pipe, ClientComputerName, ClientComputerNameLength);
309 #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
315 #endif // BOOST_PLAT_WINDOWS_DESKTOP
317 #endif // BOOST_DETAIL_WINAPI_PIPES_HPP_