main
h 213 lines 6.22 KB
Raw
1 #pragma once
2 // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
3
4
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8
9 // macro definitions
10
11 #define ReleasePipeHandle(h) if (h != INVALID_HANDLE_VALUE) { ::CloseHandle(h); h = INVALID_HANDLE_VALUE; }
12 #define ReleasePipeMessage(pMsg) if (pMsg) { PipeFreeMessage(pMsg); }
13
14
15 // constants
16
17 static const DWORD PIPE_WAIT_FOR_CONNECTION = 100; // wait a 10th of a second,
18 static const DWORD PIPE_RETRY_FOR_CONNECTION = 1800; // for up to 3 minutes.
19
20
21 // structs
22
23 typedef struct _PIPE_MESSAGE
24 {
25 DWORD dwMessageType;
26 DWORD cbData;
27
28 BOOL fAllocatedData;
29 LPVOID pvData;
30 } PIPE_MESSAGE;
31
32 typedef struct _PIPE_RPC_HANDLE
33 {
34 HANDLE hPipe;
35 CRITICAL_SECTION cs;
36
37 BOOL fInitialized;
38 BOOL fOwnHandle;
39 } PIPE_RPC_HANDLE;
40
41 typedef struct _PIPE_RPC_RESULT
42 {
43 HRESULT hr;
44
45 DWORD cbData;
46 LPBYTE pbData;
47 } PIPE_RPC_RESULT;
48
49
50 // functions
51
52 /*******************************************************************
53 PipeClientConnect - Called from the client process to connect back
54 to the pipe provided by the server process.
55
56 *******************************************************************/
57 DAPI_(HRESULT) PipeClientConnect(
58 __in_z LPCWSTR wzPipeName,
59 __out HANDLE* phPipe
60 );
61
62 /*******************************************************************
63 PipeCreate - create a duplex byte-mode named pipe compatible for use
64 with the other pipeutil functions.
65
66 *******************************************************************/
67 DAPI_(HRESULT) PipeCreate(
68 __in LPCWSTR wzName,
69 __in_opt LPSECURITY_ATTRIBUTES psa,
70 __out HANDLE* phPipe
71 );
72
73 /*******************************************************************
74 PipeOpen - opens an exist named pipe compatible for use with the other
75 pipeutil functions.
76
77 *******************************************************************/
78 DAPI_(HRESULT) PipeOpen(
79 __in_z LPCWSTR wzName,
80 __out HANDLE* phPipe
81 );
82
83 /*******************************************************************
84 PipeReadMessage - reads a message from the pipe. Free with
85 PipeFreeMessage().
86
87 *******************************************************************/
88 DAPI_(HRESULT) PipeReadMessage(
89 __in HANDLE hPipe,
90 __in PIPE_MESSAGE* pMsg
91 );
92
93 /*******************************************************************
94 PipeRpcInitiailize - initializes a RPC pipe handle from a pipe handle.
95
96 *******************************************************************/
97 DAPI_(void) PipeRpcInitialize(
98 __in PIPE_RPC_HANDLE* phRpcPipe,
99 __in HANDLE hPipe,
100 __in BOOL fTakeHandleOwnership
101 );
102
103 /*******************************************************************
104 PipeRpcInitialized - checks if a RPC pipe handle is initialized.
105
106 *******************************************************************/
107 DAPI_(BOOL) PipeRpcInitialized(
108 __in PIPE_RPC_HANDLE* phRpcPipe
109 );
110
111 /*******************************************************************
112 PipeRpcUninitiailize - uninitializes a RPC pipe handle.
113
114 *******************************************************************/
115 DAPI_(void) PipeRpcUninitiailize(
116 __in PIPE_RPC_HANDLE* phRpcPipe
117 );
118
119 /*******************************************************************
120 PipeRpcReadMessage - reads a message from the pipe. Free with
121 PipeFreeMessage().
122
123 *******************************************************************/
124 DAPI_(HRESULT) PipeRpcReadMessage(
125 __in PIPE_RPC_HANDLE* phRpcPipe,
126 __in PIPE_MESSAGE* pMsg
127 );
128
129 /*******************************************************************
130 PipeRpcRequest - sends message and reads a response over the pipe.
131 Free with PipeFreeRpcResult().
132
133 *******************************************************************/
134 DAPI_(HRESULT) PipeRpcRequest(
135 __in PIPE_RPC_HANDLE* phRpcPipe,
136 __in DWORD dwMessageType,
137 __in_bcount(cbArgs) LPVOID pbArgs,
138 __in SIZE_T cbArgs,
139 __in PIPE_RPC_RESULT* pResult
140 );
141
142 /*******************************************************************
143 PipeRpcResponse - sends response over the pipe.
144
145 *******************************************************************/
146 DAPI_(HRESULT) PipeRpcResponse(
147 __in PIPE_RPC_HANDLE* phPipe,
148 __in DWORD dwMessageType,
149 __in HRESULT hrResult,
150 __in_bcount(cbResult) LPVOID pvResult,
151 __in SIZE_T cbResult
152 );
153
154 /*******************************************************************
155 PipeRpcWriteMessage - writes a message to the pipe.
156
157 *******************************************************************/
158 DAPI_(HRESULT) PipeRpcWriteMessage(
159 __in PIPE_RPC_HANDLE* phPipe,
160 __in DWORD dwMessageType,
161 __in_bcount_opt(cbData) LPVOID pvData,
162 __in SIZE_T cbData
163 );
164
165 /*******************************************************************
166 PipeWriteDisconnect - writes a message to the pipe indicating the
167 client should disconnect.
168
169 *******************************************************************/
170 DAPI_(HRESULT) PipeWriteDisconnect(
171 __in HANDLE hPipe
172 );
173
174 /*******************************************************************
175 PipeFreeMessage - frees any memory allocated in PipeReadMessage.
176
177 *******************************************************************/
178 DAPI_(void) PipeFreeMessage(
179 __in PIPE_MESSAGE* pMsg
180 );
181
182 /*******************************************************************
183 PipeFreeRpcResult - frees any memory allocated in PipeRpcRequest.
184
185 *******************************************************************/
186 DAPI_(void) PipeFreeRpcResult(
187 __in PIPE_RPC_RESULT* pResult
188 );
189
190 /*******************************************************************
191 PipeServerWaitForClientConnect - Called from the server process to
192 wait for a client to connect back to the provided pipe.
193
194 *******************************************************************/
195 DAPI_(HRESULT) PipeServerWaitForClientConnect(
196 __in HANDLE hClientProcess,
197 __in HANDLE hPipe
198 );
199
200 /*******************************************************************
201 PipeWriteMessage - writes a message to the pipe.
202
203 *******************************************************************/
204 DAPI_(HRESULT) PipeWriteMessage(
205 __in HANDLE hPipe,
206 __in DWORD dwMessageType,
207 __in_bcount_opt(cbData) LPVOID pvData,
208 __in SIZE_T cbData
209 );
210
211 #ifdef __cplusplus
212 }
213 #endif