pipes.hpp 11 KB

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