pipes.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * Copyright 2016 Klemens D. Morgenstern
  3. * Copyright 2016, 2017 Andrey Semashev
  4. *
  5. * Distributed under the Boost Software License, Version 1.0.
  6. * See http://www.boost.org/LICENSE_1_0.txt
  7. */
  8. #ifndef BOOST_WINAPI_PIPES_HPP_INCLUDED_
  9. #define BOOST_WINAPI_PIPES_HPP_INCLUDED_
  10. #include <boost/winapi/basic_types.hpp>
  11. #include <boost/winapi/config.hpp>
  12. #include <boost/winapi/overlapped.hpp>
  13. #ifdef BOOST_HAS_PRAGMA_ONCE
  14. #pragma once
  15. #endif
  16. #if BOOST_WINAPI_PARTITION_DESKTOP_SYSTEM
  17. #if !defined( BOOST_USE_WINDOWS_H ) && BOOST_WINAPI_PARTITION_DESKTOP && !defined( BOOST_NO_ANSI_APIS )
  18. extern "C" {
  19. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC CreateNamedPipeA(
  20. boost::winapi::LPCSTR_ lpName,
  21. boost::winapi::DWORD_ dwOpenMode,
  22. boost::winapi::DWORD_ dwPipeMode,
  23. boost::winapi::DWORD_ nMaxInstances,
  24. boost::winapi::DWORD_ nOutBufferSize,
  25. boost::winapi::DWORD_ nInBufferSize,
  26. boost::winapi::DWORD_ nDefaultTimeOut,
  27. _SECURITY_ATTRIBUTES *lpSecurityAttributes);
  28. } // extern "C"
  29. #endif // !defined( BOOST_USE_WINDOWS_H ) && BOOST_WINAPI_PARTITION_DESKTOP && !defined( BOOST_NO_ANSI_APIS )
  30. #if !defined( BOOST_USE_WINDOWS_H )
  31. extern "C" {
  32. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC ImpersonateNamedPipeClient(
  33. boost::winapi::HANDLE_ hNamedPipe);
  34. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC CreatePipe(
  35. boost::winapi::PHANDLE_ hReadPipe,
  36. boost::winapi::PHANDLE_ hWritePipe,
  37. _SECURITY_ATTRIBUTES* lpPipeAttributes,
  38. boost::winapi::DWORD_ nSize);
  39. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC ConnectNamedPipe(
  40. boost::winapi::HANDLE_ hNamedPipe,
  41. _OVERLAPPED* lpOverlapped);
  42. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC DisconnectNamedPipe(
  43. boost::winapi::HANDLE_ hNamedPipe);
  44. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC SetNamedPipeHandleState(
  45. boost::winapi::HANDLE_ hNamedPipe,
  46. boost::winapi::LPDWORD_ lpMode,
  47. boost::winapi::LPDWORD_ lpMaxCollectionCount,
  48. boost::winapi::LPDWORD_ lpCollectDataTimeout);
  49. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC PeekNamedPipe(
  50. boost::winapi::HANDLE_ hNamedPipe,
  51. boost::winapi::LPVOID_ lpBuffer,
  52. boost::winapi::DWORD_ nBufferSize,
  53. boost::winapi::LPDWORD_ lpBytesRead,
  54. boost::winapi::LPDWORD_ lpTotalBytesAvail,
  55. boost::winapi::LPDWORD_ lpBytesLeftThisMessage);
  56. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC TransactNamedPipe(
  57. boost::winapi::HANDLE_ hNamedPipe,
  58. boost::winapi::LPVOID_ lpInBuffer,
  59. boost::winapi::DWORD_ nInBufferSize,
  60. boost::winapi::LPVOID_ lpOutBuffer,
  61. boost::winapi::DWORD_ nOutBufferSize,
  62. boost::winapi::LPDWORD_ lpBytesRead,
  63. _OVERLAPPED* lpOverlapped);
  64. #if !defined( BOOST_NO_ANSI_APIS )
  65. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC WaitNamedPipeA(
  66. boost::winapi::LPCSTR_ lpNamedPipeName,
  67. boost::winapi::DWORD_ nTimeOut);
  68. #endif // !defined( BOOST_NO_ANSI_APIS )
  69. BOOST_SYMBOL_IMPORT boost::winapi::HANDLE_ BOOST_WINAPI_WINAPI_CC CreateNamedPipeW(
  70. boost::winapi::LPCWSTR_ lpName,
  71. boost::winapi::DWORD_ dwOpenMode,
  72. boost::winapi::DWORD_ dwPipeMode,
  73. boost::winapi::DWORD_ nMaxInstances,
  74. boost::winapi::DWORD_ nOutBufferSize,
  75. boost::winapi::DWORD_ nInBufferSize,
  76. boost::winapi::DWORD_ nDefaultTimeOut,
  77. _SECURITY_ATTRIBUTES* lpSecurityAttributes);
  78. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC WaitNamedPipeW(
  79. boost::winapi::LPCWSTR_ lpNamedPipeName,
  80. boost::winapi::DWORD_ nTimeOut);
  81. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  82. #if !defined( BOOST_NO_ANSI_APIS )
  83. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC GetNamedPipeClientComputerNameA(
  84. boost::winapi::HANDLE_ Pipe,
  85. boost::winapi::LPSTR_ ClientComputerName,
  86. boost::winapi::ULONG_ ClientComputerNameLength);
  87. #endif // !defined( BOOST_NO_ANSI_APIS )
  88. BOOST_SYMBOL_IMPORT boost::winapi::BOOL_ BOOST_WINAPI_WINAPI_CC GetNamedPipeClientComputerNameW(
  89. boost::winapi::HANDLE_ Pipe,
  90. boost::winapi::LPWSTR_ ClientComputerName,
  91. boost::winapi::ULONG_ ClientComputerNameLength);
  92. #endif
  93. } // extern "C"
  94. #endif // !defined( BOOST_USE_WINDOWS_H )
  95. namespace boost {
  96. namespace winapi {
  97. #if defined( BOOST_USE_WINDOWS_H )
  98. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_DUPLEX_ = PIPE_ACCESS_DUPLEX;
  99. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_INBOUND_ = PIPE_ACCESS_INBOUND;
  100. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_OUTBOUND_ = PIPE_ACCESS_OUTBOUND;
  101. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_TYPE_BYTE_ = PIPE_TYPE_BYTE;
  102. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_TYPE_MESSAGE_ = PIPE_TYPE_MESSAGE;
  103. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_READMODE_BYTE_ = PIPE_READMODE_BYTE;
  104. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_READMODE_MESSAGE_ = PIPE_READMODE_MESSAGE;
  105. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_WAIT_ = PIPE_WAIT;
  106. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_NOWAIT_ = PIPE_NOWAIT;
  107. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_UNLIMITED_INSTANCES_ = PIPE_UNLIMITED_INSTANCES;
  108. BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_USE_DEFAULT_WAIT_ = NMPWAIT_USE_DEFAULT_WAIT;
  109. BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_NOWAIT_ = NMPWAIT_NOWAIT;
  110. BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_WAIT_FOREVER_ = NMPWAIT_WAIT_FOREVER;
  111. #else // defined( BOOST_USE_WINDOWS_H )
  112. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_DUPLEX_ = 0x00000003;
  113. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_INBOUND_ = 0x00000001;
  114. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCESS_OUTBOUND_ = 0x00000002;
  115. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_TYPE_BYTE_ = 0x00000000;
  116. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_TYPE_MESSAGE_ = 0x00000004;
  117. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_READMODE_BYTE_ = 0x00000000;
  118. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_READMODE_MESSAGE_ = 0x00000002;
  119. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_WAIT_ = 0x00000000;
  120. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_NOWAIT_ = 0x00000001;
  121. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_UNLIMITED_INSTANCES_ = 255u;
  122. BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_USE_DEFAULT_WAIT_ = 0x00000000;
  123. BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_NOWAIT_ = 0x00000001;
  124. BOOST_CONSTEXPR_OR_CONST DWORD_ NMPWAIT_WAIT_FOREVER_ = 0xFFFFFFFF;
  125. #endif // defined( BOOST_USE_WINDOWS_H )
  126. // These constants are not defined in Windows SDK prior to 7.0A
  127. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_ACCEPT_REMOTE_CLIENTS_ = 0x00000000;
  128. BOOST_CONSTEXPR_OR_CONST DWORD_ PIPE_REJECT_REMOTE_CLIENTS_ = 0x00000008;
  129. using ::ImpersonateNamedPipeClient;
  130. using ::DisconnectNamedPipe;
  131. using ::SetNamedPipeHandleState;
  132. using ::PeekNamedPipe;
  133. #if !defined( BOOST_NO_ANSI_APIS )
  134. using ::WaitNamedPipeA;
  135. #endif
  136. using ::WaitNamedPipeW;
  137. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  138. #if !defined( BOOST_NO_ANSI_APIS )
  139. using ::GetNamedPipeClientComputerNameA;
  140. #endif // !defined( BOOST_NO_ANSI_APIS )
  141. using ::GetNamedPipeClientComputerNameW;
  142. #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  143. BOOST_FORCEINLINE BOOL_ CreatePipe(PHANDLE_ hReadPipe, PHANDLE_ hWritePipe, LPSECURITY_ATTRIBUTES_ lpPipeAttributes, DWORD_ nSize)
  144. {
  145. return ::CreatePipe(hReadPipe, hWritePipe, reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpPipeAttributes), nSize);
  146. }
  147. BOOST_FORCEINLINE BOOL_ ConnectNamedPipe(HANDLE_ hNamedPipe, LPOVERLAPPED_ lpOverlapped)
  148. {
  149. return ::ConnectNamedPipe(hNamedPipe, reinterpret_cast< ::_OVERLAPPED* >(lpOverlapped));
  150. }
  151. BOOST_FORCEINLINE BOOL_ TransactNamedPipe(HANDLE_ hNamedPipe, LPVOID_ lpInBuffer, DWORD_ nInBufferSize, LPVOID_ lpOutBuffer, DWORD_ nOutBufferSize, LPDWORD_ lpBytesRead, LPOVERLAPPED_ lpOverlapped)
  152. {
  153. return ::TransactNamedPipe(hNamedPipe, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesRead, reinterpret_cast< ::_OVERLAPPED* >(lpOverlapped));
  154. }
  155. #if BOOST_WINAPI_PARTITION_DESKTOP && !defined( BOOST_NO_ANSI_APIS )
  156. BOOST_FORCEINLINE HANDLE_ CreateNamedPipeA(
  157. LPCSTR_ lpName,
  158. DWORD_ dwOpenMode,
  159. DWORD_ dwPipeMode,
  160. DWORD_ nMaxInstances,
  161. DWORD_ nOutBufferSize,
  162. DWORD_ nInBufferSize,
  163. DWORD_ nDefaultTimeOut,
  164. LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
  165. {
  166. return ::CreateNamedPipeA(
  167. lpName,
  168. dwOpenMode,
  169. dwPipeMode,
  170. nMaxInstances,
  171. nOutBufferSize,
  172. nInBufferSize,
  173. nDefaultTimeOut,
  174. reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
  175. }
  176. BOOST_FORCEINLINE HANDLE_ create_named_pipe(
  177. LPCSTR_ lpName,
  178. DWORD_ dwOpenMode,
  179. DWORD_ dwPipeMode,
  180. DWORD_ nMaxInstances,
  181. DWORD_ nOutBufferSize,
  182. DWORD_ nInBufferSize,
  183. DWORD_ nDefaultTimeOut,
  184. LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
  185. {
  186. return ::CreateNamedPipeA(
  187. lpName,
  188. dwOpenMode,
  189. dwPipeMode,
  190. nMaxInstances,
  191. nOutBufferSize,
  192. nInBufferSize,
  193. nDefaultTimeOut,
  194. reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
  195. }
  196. #endif // BOOST_WINAPI_PARTITION_DESKTOP && !defined( BOOST_NO_ANSI_APIS )
  197. BOOST_FORCEINLINE HANDLE_ CreateNamedPipeW(
  198. LPCWSTR_ lpName,
  199. DWORD_ dwOpenMode,
  200. DWORD_ dwPipeMode,
  201. DWORD_ nMaxInstances,
  202. DWORD_ nOutBufferSize,
  203. DWORD_ nInBufferSize,
  204. DWORD_ nDefaultTimeOut,
  205. LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
  206. {
  207. return ::CreateNamedPipeW(
  208. lpName,
  209. dwOpenMode,
  210. dwPipeMode,
  211. nMaxInstances,
  212. nOutBufferSize,
  213. nInBufferSize,
  214. nDefaultTimeOut,
  215. reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
  216. }
  217. BOOST_FORCEINLINE HANDLE_ create_named_pipe(
  218. LPCWSTR_ lpName,
  219. DWORD_ dwOpenMode,
  220. DWORD_ dwPipeMode,
  221. DWORD_ nMaxInstances,
  222. DWORD_ nOutBufferSize,
  223. DWORD_ nInBufferSize,
  224. DWORD_ nDefaultTimeOut,
  225. LPSECURITY_ATTRIBUTES_ lpSecurityAttributes)
  226. {
  227. return ::CreateNamedPipeW(
  228. lpName,
  229. dwOpenMode,
  230. dwPipeMode,
  231. nMaxInstances,
  232. nOutBufferSize,
  233. nInBufferSize,
  234. nDefaultTimeOut,
  235. reinterpret_cast< ::_SECURITY_ATTRIBUTES* >(lpSecurityAttributes));
  236. }
  237. #if !defined( BOOST_NO_ANSI_APIS )
  238. BOOST_FORCEINLINE BOOL_ wait_named_pipe(LPCSTR_ lpNamedPipeName, DWORD_ nTimeOut)
  239. {
  240. return ::WaitNamedPipeA(lpNamedPipeName, nTimeOut);
  241. }
  242. #endif //BOOST_NO_ANSI_APIS
  243. BOOST_FORCEINLINE BOOL_ wait_named_pipe(LPCWSTR_ lpNamedPipeName, DWORD_ nTimeOut)
  244. {
  245. return ::WaitNamedPipeW(lpNamedPipeName, nTimeOut);
  246. }
  247. #if BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  248. #if !defined( BOOST_NO_ANSI_APIS )
  249. BOOST_FORCEINLINE BOOL_ get_named_pipe_client_computer_name(HANDLE_ Pipe, LPSTR_ ClientComputerName, ULONG_ ClientComputerNameLength)
  250. {
  251. return ::GetNamedPipeClientComputerNameA(Pipe, ClientComputerName, ClientComputerNameLength);
  252. }
  253. #endif // !defined( BOOST_NO_ANSI_APIS )
  254. BOOST_FORCEINLINE BOOL_ get_named_pipe_client_computer_name(HANDLE_ Pipe, LPWSTR_ ClientComputerName, ULONG_ ClientComputerNameLength)
  255. {
  256. return ::GetNamedPipeClientComputerNameW(Pipe, ClientComputerName, ClientComputerNameLength);
  257. }
  258. #endif // BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6
  259. }
  260. }
  261. #endif // BOOST_WINAPI_PARTITION_DESKTOP_SYSTEM
  262. #endif // BOOST_WINAPI_PIPES_HPP_INCLUDED_