2 * Copyright 2016 Klemens D. Morgenstern
3 * Copyright 2016, 2017 Andrey Semashev
5 * Distributed under the Boost Software License, Version 1.0.
6 * See http://www.boost.org/LICENSE_1_0.txt
9 #ifndef BOOST_WINAPI_PIPES_HPP_INCLUDED_
10 #define BOOST_WINAPI_PIPES_HPP_INCLUDED_
12 #include <boost/winapi/basic_types.hpp>
13 #include <boost/winapi/config.hpp>
14 #include <boost/winapi/overlapped.hpp>
16 #ifdef BOOST_HAS_PRAGMA_ONCE
20 #if BOOST_WINAPI_PARTITION_DESKTOP_SYSTEM
22 #include <boost/winapi/detail/header.hpp>
24 #if !defined( BOOST_USE_WINDOWS_H ) && BOOST_WINAPI_PARTITION_DESKTOP && !defined( BOOST_NO_ANSI_APIS )
26 BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC CreateNamedPipeA(
27 boost::winapi::LPCSTR_ lpName,
28 boost::winapi::DWORD_ dwOpenMode,
29 boost::winapi::DWORD_ dwPipeMode,
30 boost::winapi::DWORD_ nMaxInstances,
31 boost::winapi::DWORD_ nOutBufferSize,
32 boost::winapi::DWORD_ nInBufferSize,
33 boost::winapi::DWORD_ nDefaultTimeOut,
34 _SECURITY_ATTRIBUTES *lpSecurityAttributes);
36 #endif // !defined( BOOST_USE_WINDOWS_H ) && BOOST_WINAPI_PARTITION_DESKTOP && !defined( BOOST_NO_ANSI_APIS )
38 #if !defined( BOOST_USE_WINDOWS_H )
41 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC ImpersonateNamedPipeClient(
42 boost::winapi::HANDLE_ hNamedPipe);
44 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC CreatePipe(
45 boost::winapi::PHANDLE_ hReadPipe,
46 boost::winapi::PHANDLE_ hWritePipe,
47 _SECURITY_ATTRIBUTES* lpPipeAttributes,
48 boost::winapi::DWORD_ nSize);
50 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC ConnectNamedPipe(
51 boost::winapi::HANDLE_ hNamedPipe,
52 _OVERLAPPED* lpOverlapped);
54 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC DisconnectNamedPipe(
55 boost::winapi::HANDLE_ hNamedPipe);
57 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC SetNamedPipeHandleState(
58 boost::winapi::HANDLE_ hNamedPipe,
59 boost::winapi::LPDWORD_ lpMode,
60 boost::winapi::LPDWORD_ lpMaxCollectionCount,
61 boost::winapi::LPDWORD_ lpCollectDataTimeout);
63 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC PeekNamedPipe(
64 boost::winapi::HANDLE_ hNamedPipe,
65 boost::winapi::LPVOID_ lpBuffer,
66 boost::winapi::DWORD_ nBufferSize,
67 boost::winapi::LPDWORD_ lpBytesRead,
68 boost::winapi::LPDWORD_ lpTotalBytesAvail,
69 boost::winapi::LPDWORD_ lpBytesLeftThisMessage);
71 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC TransactNamedPipe(
72 boost::winapi::HANDLE_ hNamedPipe,
73 boost::winapi::LPVOID_ lpInBuffer,
74 boost::winapi::DWORD_ nInBufferSize,
75 boost::winapi::LPVOID_ lpOutBuffer,
76 boost::winapi::DWORD_ nOutBufferSize,
77 boost::winapi::LPDWORD_ lpBytesRead,
78 _OVERLAPPED* lpOverlapped);
80 #if !defined( BOOST_NO_ANSI_APIS )
81 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC WaitNamedPipeA(
82 boost::winapi::LPCSTR_ lpNamedPipeName,
83 boost::winapi::DWORD_ nTimeOut);
84 #endif // !defined( BOOST_NO_ANSI_APIS )
86 BOOST_WINAPI_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC CreateNamedPipeW(
87 boost::winapi::LPCWSTR_ lpName,
88 boost::winapi::DWORD_ dwOpenMode,
89 boost::winapi::DWORD_ dwPipeMode,
90 boost::winapi::DWORD_ nMaxInstances,
91 boost::winapi::DWORD_ nOutBufferSize,
92 boost::winapi::DWORD_ nInBufferSize,
93 boost::winapi::DWORD_ nDefaultTimeOut,
94 _SECURITY_ATTRIBUTES* lpSecurityAttributes);
96 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC WaitNamedPipeW(
97 boost::winapi::LPCWSTR_ lpNamedPipeName,
98 boost::winapi::DWORD_ nTimeOut);
100 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
101 #if !defined( BOOST_NO_ANSI_APIS )
102 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC GetNamedPipeClientComputerNameA(
103 boost::winapi::HANDLE_ Pipe,
104 boost::winapi::LPSTR_ ClientComputerName,
105 boost::winapi::ULONG_ ClientComputerNameLength);
106 #endif // !defined( BOOST_NO_ANSI_APIS )
108 BOOST_WINAPI_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC GetNamedPipeClientComputerNameW(
109 boost::winapi::HANDLE_ Pipe,
110 boost::winapi::LPWSTR_ ClientComputerName,
111 boost::winapi::ULONG_ ClientComputerNameLength);
115 #endif // !defined( BOOST_USE_WINDOWS_H )
120 #if defined( BOOST_USE_WINDOWS_H )
122 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_DUPLEX_ = PIPE_ACCESS_DUPLEX;
123 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_INBOUND_ = PIPE_ACCESS_INBOUND;
124 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_OUTBOUND_ = PIPE_ACCESS_OUTBOUND;
126 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_TYPE_BYTE_ = PIPE_TYPE_BYTE;
127 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_TYPE_MESSAGE_ = PIPE_TYPE_MESSAGE;
129 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_READMODE_BYTE_ = PIPE_READMODE_BYTE;
130 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_READMODE_MESSAGE_ = PIPE_READMODE_MESSAGE;
132 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_WAIT_ = PIPE_WAIT;
133 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_NOWAIT_ = PIPE_NOWAIT;
135 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_UNLIMITED_INSTANCES_ = PIPE_UNLIMITED_INSTANCES;
137 BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_USE_DEFAULT_WAIT_ = NMPWAIT_USE_DEFAULT_WAIT;
138 BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_NOWAIT_ = NMPWAIT_NOWAIT;
139 BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_WAIT_FOREVER_ = NMPWAIT_WAIT_FOREVER;
141 #else // defined( BOOST_USE_WINDOWS_H )
143 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_DUPLEX_ = 0x00000003;
144 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_INBOUND_ = 0x00000001;
145 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_OUTBOUND_ = 0x00000002;
147 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_TYPE_BYTE_ = 0x00000000;
148 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_TYPE_MESSAGE_ = 0x00000004;
150 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_READMODE_BYTE_ = 0x00000000;
151 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_READMODE_MESSAGE_ = 0x00000002;
153 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_WAIT_ = 0x00000000;
154 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_NOWAIT_ = 0x00000001;
156 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_UNLIMITED_INSTANCES_ = 255u;
158 BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_USE_DEFAULT_WAIT_ = 0x00000000;
159 BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_NOWAIT_ = 0x00000001;
160 BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_WAIT_FOREVER_ = 0xFFFFFFFF;
162 #endif // defined( BOOST_USE_WINDOWS_H )
164 // These constants are not defined in Windows SDK prior to 7.0A
165 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCEPT_REMOTE_CLIENTS_ = 0x00000000;
166 BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_REJECT_REMOTE_CLIENTS_ = 0x00000008;
168 using ::ImpersonateNamedPipeClient;
169 using ::DisconnectNamedPipe;
170 using ::SetNamedPipeHandleState;
171 using ::PeekNamedPipe;
173 #if !defined( BOOST_NO_ANSI_APIS )
174 using ::WaitNamedPipeA;
176 using ::WaitNamedPipeW;
178 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
179 #if !defined( BOOST_NO_ANSI_APIS )
180 using ::GetNamedPipeClientComputerNameA;
181 #endif // !defined( BOOST_NO_ANSI_APIS )
182 using ::GetNamedPipeClientComputerNameW;
183 #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
185 BOOST_FORCEINLINE BOOL_ CreatePipe(PHANDLE_ hReadPipe, PHANDLE_ hWritePipe, LPSECURITY_ATTRIBUTES_ lpPipeAttributes, DWORD_ nSize)
187 return ::CreatePipe(hReadPipe, hWritePipe, reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpPipeAttributes), nSize);
190 BOOST_FORCEINLINE BOOL_ ConnectNamedPipe(HANDLE_ hNamedPipe, LPOVERLAPPED_ lpOverlapped)
192 return ::ConnectNamedPipe(hNamedPipe, reinterpret_cast< ::_OVERLAPPED* >(lpOverlapped));
195 BOOST_FORCEINLINE BOOL_ TransactNamedPipe(HANDLE_ hNamedPipe, LPVOID_ lpInBuffer, DWORD_ nInBufferSize, LPVOID_ lpOutBuffer, DWORD_ nOutBufferSize, LPDWORD_ lpBytesRead, LPOVERLAPPED_ lpOverlapped)
197 return ::TransactNamedPipe(hNamedPipe, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesRead, reinterpret_cast< ::_OVERLAPPED* >(lpOverlapped));
201 #if BOOST_WINAPI_PARTITION_DESKTOP && !defined( BOOST_NO_ANSI_APIS )
202 BOOST_FORCEINLINE HANDLE_ CreateNamedPipeA(
206 DWORD_ nMaxInstances,
207 DWORD_ nOutBufferSize,
208 DWORD_ nInBufferSize,
209 DWORD_ nDefaultTimeOut,
210 LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
212 return ::CreateNamedPipeA(
220 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
223 BOOST_FORCEINLINE HANDLE_ create_named_pipe(
227 DWORD_ nMaxInstances,
228 DWORD_ nOutBufferSize,
229 DWORD_ nInBufferSize,
230 DWORD_ nDefaultTimeOut,
231 LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
233 return ::CreateNamedPipeA(
241 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
243 #endif // BOOST_WINAPI_PARTITION_DESKTOP && !defined( BOOST_NO_ANSI_APIS )
245 BOOST_FORCEINLINE HANDLE_ CreateNamedPipeW(
249 DWORD_ nMaxInstances,
250 DWORD_ nOutBufferSize,
251 DWORD_ nInBufferSize,
252 DWORD_ nDefaultTimeOut,
253 LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
255 return ::CreateNamedPipeW(
263 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
266 BOOST_FORCEINLINE HANDLE_ create_named_pipe(
270 DWORD_ nMaxInstances,
271 DWORD_ nOutBufferSize,
272 DWORD_ nInBufferSize,
273 DWORD_ nDefaultTimeOut,
274 LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
276 return ::CreateNamedPipeW(
284 reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
287 #if !defined( BOOST_NO_ANSI_APIS )
288 BOOST_FORCEINLINE BOOL_ wait_named_pipe(LPCSTR_ lpNamedPipeName, DWORD_ nTimeOut)
290 return ::WaitNamedPipeA(lpNamedPipeName, nTimeOut);
292 #endif //BOOST_NO_ANSI_APIS
294 BOOST_FORCEINLINE BOOL_ wait_named_pipe(LPCWSTR_ lpNamedPipeName, DWORD_ nTimeOut)
296 return ::WaitNamedPipeW(lpNamedPipeName, nTimeOut);
299 #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
301 #if !defined( BOOST_NO_ANSI_APIS )
302 BOOST_FORCEINLINE BOOL_ get_named_pipe_client_computer_name(HANDLE_ Pipe, LPSTR_ ClientComputerName, ULONG_ ClientComputerNameLength)
304 return ::GetNamedPipeClientComputerNameA(Pipe, ClientComputerName, ClientComputerNameLength);
306 #endif // !defined( BOOST_NO_ANSI_APIS )
308 BOOST_FORCEINLINE BOOL_ get_named_pipe_client_computer_name(HANDLE_ Pipe, LPWSTR_ ClientComputerName, ULONG_ ClientComputerNameLength)
310 return ::GetNamedPipeClientComputerNameW(Pipe, ClientComputerName, ClientComputerNameLength);
313 #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
318 #include <boost/winapi/detail/footer.hpp>
320 #endif // BOOST_WINAPI_PARTITION_DESKTOP_SYSTEM
322 #endif // BOOST_WINAPI_PIPES_HPP_INCLUDED_