[KERNEL32]
[reactos.git] / reactos / dll / win32 / rpcrt4 / rpcrt4_ros.diff
1 Index: epm_towers.h
2 ===================================================================
3 --- epm_towers.h (working copy)
4 +++ epm_towers.h (working copy)
5 @@ -17,11 +17,11 @@
6 * License along with this library; if not, write to the Free Software
7 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
8 *
9 */
10
11 -#include "epm.h"
12 +#include "epm_c.h"
13
14 #define EPM_PROTOCOL_DNET_NSP 0x04
15 #define EPM_PROTOCOL_OSI_TP4 0x05
16 #define EPM_PROTOCOL_OSI_CLNS 0x06
17 #define EPM_PROTOCOL_TCP 0x07
18 Index: rpc_epmap.c
19 ===================================================================
20 --- rpc_epmap.c (working copy)
21 +++ rpc_epmap.c (working copy)
22 @@ -30,11 +30,11 @@
23
24 #include "wine/debug.h"
25 #include "wine/exception.h"
26
27 #include "rpc_binding.h"
28 -#include "epm.h"
29 +#include "epm_c.h"
30 #include "epm_towers.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(ole);
33
34 /* The "real" RPC portmapper endpoints that I know of are:
35 Index: rpc_server.c
36 ===================================================================
37 --- rpc_server.c (working copy)
38 +++ rpc_server.c (working copy)
39 @@ -1040,22 +1040,28 @@
40 /***********************************************************************
41 * RpcMgmtServerWaitListen (RPCRT4.@)
42 */
43 RPC_STATUS WINAPI RpcMgmtWaitServerListen( void )
44 {
45 - TRACE("()\n");
46 + RpcServerProtseq *cps;
47
48 EnterCriticalSection(&listen_cs);
49
50 if (!std_listen) {
51 LeaveCriticalSection(&listen_cs);
52 return RPC_S_NOT_LISTENING;
53 }
54
55 + do {
56 LeaveCriticalSection(&listen_cs);
57 + LIST_FOR_EACH_ENTRY(cps, &protseqs, RpcServerProtseq, entry)
58 + WaitForSingleObject(cps->server_ready_event, INFINITE);
59
60 - FIXME("not waiting for server calls to finish\n");
61 + EnterCriticalSection(&listen_cs);
62 + } while (!std_listen);
63 +
64 + LeaveCriticalSection(&listen_cs);
65
66 return RPC_S_OK;
67 }
68
69 /***********************************************************************
70 Index: rpc_transport.c
71 ===================================================================
72 --- rpc_transport.c (working copy)
73 +++ rpc_transport.c (working copy)
74 @@ -65,10 +65,13 @@
75 # include <sys/poll.h>
76 # endif
77 # define closesocket close
78 #endif /* defined(__MINGW32__) || defined (_MSC_VER) */
79
80 +#include <winsock2.h>
81 +#include <ws2tcpip.h>
82 +
83 #include "windef.h"
84 #include "winbase.h"
85 #include "winnls.h"
86 #include "winerror.h"
87 #include "winternl.h"
88 @@ -82,10 +85,12 @@
89 #include "rpc_binding.h"
90 #include "rpc_message.h"
91 #include "rpc_server.h"
92 #include "epm_towers.h"
93
94 +#include "unix_func.h"
95 +
96 #ifndef SOL_TCP
97 # define SOL_TCP IPPROTO_TCP
98 #endif
99
100 WINE_DEFAULT_DEBUG_CHANNEL(rpc);
101 @@ -94,11 +99,11 @@
102
103 typedef struct _RpcConnection_np
104 {
105 RpcConnection common;
106 HANDLE pipe;
107 - OVERLAPPED ovl;
108 + OVERLAPPED ovl[2];
109 BOOL listening;
110 } RpcConnection_np;
111
112 static RpcConnection *rpcrt4_conn_np_alloc(void)
113 {
114 @@ -118,17 +123,17 @@
115 return RPC_S_OK;
116
117 npc->listening = TRUE;
118 for (;;)
119 {
120 - if (ConnectNamedPipe(npc->pipe, &npc->ovl))
121 + if (ConnectNamedPipe(npc->pipe, &npc->ovl[0]))
122 return RPC_S_OK;
123
124 switch(GetLastError())
125 {
126 case ERROR_PIPE_CONNECTED:
127 - SetEvent(npc->ovl.hEvent);
128 + SetEvent(npc->ovl[0].hEvent);
129 return RPC_S_OK;
130 case ERROR_IO_PENDING:
131 /* will be completed in rpcrt4_protseq_np_wait_for_new_connection */
132 return RPC_S_OK;
133 case ERROR_NO_DATA_DETECTED:
134 @@ -146,11 +151,11 @@
135 static RPC_STATUS rpcrt4_conn_create_pipe(RpcConnection *Connection, LPCSTR pname)
136 {
137 RpcConnection_np *npc = (RpcConnection_np *) Connection;
138 TRACE("listening on %s\n", pname);
139
140 - npc->pipe = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX,
141 + npc->pipe = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
142 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE,
143 PIPE_UNLIMITED_INSTANCES,
144 RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL);
145 if (npc->pipe == INVALID_HANDLE_VALUE) {
146 WARN("CreateNamedPipe failed with error %d\n", GetLastError());
147 @@ -159,11 +164,12 @@
148 else
149 return RPC_S_CANT_CREATE_ENDPOINT;
150 }
151
152 memset(&npc->ovl, 0, sizeof(npc->ovl));
153 - npc->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
154 + npc->ovl[0].hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
155 + npc->ovl[1].hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
156
157 /* Note: we don't call ConnectNamedPipe here because it must be done in the
158 * server thread as the thread must be alertable */
159 return RPC_S_OK;
160 }
161 @@ -220,11 +226,12 @@
162 /* success */
163 memset(&npc->ovl, 0, sizeof(npc->ovl));
164 /* pipe is connected; change to message-read mode. */
165 dwMode = PIPE_READMODE_MESSAGE;
166 SetNamedPipeHandleState(pipe, &dwMode, NULL, NULL);
167 - npc->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
168 + npc->ovl[0].hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
169 + npc->ovl[1].hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
170 npc->pipe = pipe;
171
172 return RPC_S_OK;
173 }
174
175 @@ -326,11 +333,12 @@
176 {
177 /* because of the way named pipes work, we'll transfer the connected pipe
178 * to the child, then reopen the server binding to continue listening */
179
180 new_npc->pipe = old_npc->pipe;
181 - new_npc->ovl = old_npc->ovl;
182 + new_npc->ovl[0] = old_npc->ovl[0];
183 + new_npc->ovl[1] = old_npc->ovl[1];
184 old_npc->pipe = 0;
185 memset(&old_npc->ovl, 0, sizeof(old_npc->ovl));
186 old_npc->listening = FALSE;
187 }
188
189 @@ -377,13 +385,18 @@
190 unsigned int bytes_left = count;
191
192 while (bytes_left)
193 {
194 DWORD bytes_read;
195 - ret = ReadFile(npc->pipe, buf, bytes_left, &bytes_read, NULL);
196 - if (!ret || !bytes_read)
197 + ret = ReadFile(npc->pipe, buf, bytes_left, &bytes_read, &npc->ovl[0]);
198 + if ((!ret || !bytes_read) && (GetLastError() != ERROR_IO_PENDING))
199 + break;
200 +
201 + ret = GetOverlappedResult(npc->pipe, &npc->ovl[0], &bytes_read, TRUE);
202 + if (!ret && (GetLastError() != ERROR_MORE_DATA))
203 break;
204 +
205 bytes_left -= bytes_read;
206 buf += bytes_read;
207 }
208 return ret ? count : -1;
209 }
210 @@ -397,13 +410,18 @@
211 unsigned int bytes_left = count;
212
213 while (bytes_left)
214 {
215 DWORD bytes_written;
216 - ret = WriteFile(npc->pipe, buf, bytes_left, &bytes_written, NULL);
217 - if (!ret || !bytes_written)
218 + ret = WriteFile(npc->pipe, buf, bytes_left, &bytes_written, &npc->ovl[1]);
219 + if ((!ret || !bytes_written) && (GetLastError() != ERROR_IO_PENDING))
220 + break;
221 +
222 + ret = GetOverlappedResult(npc->pipe, &npc->ovl[1], &bytes_written, TRUE);
223 + if (!ret && (GetLastError() != ERROR_MORE_DATA))
224 break;
225 +
226 bytes_left -= bytes_written;
227 buf += bytes_written;
228 }
229 return ret ? count : -1;
230 }
231 @@ -414,13 +432,17 @@
232 if (npc->pipe) {
233 FlushFileBuffers(npc->pipe);
234 CloseHandle(npc->pipe);
235 npc->pipe = 0;
236 }
237 - if (npc->ovl.hEvent) {
238 - CloseHandle(npc->ovl.hEvent);
239 - npc->ovl.hEvent = 0;
240 + if (npc->ovl[0].hEvent) {
241 + CloseHandle(npc->ovl[0].hEvent);
242 + npc->ovl[0].hEvent = 0;
243 + }
244 + if (npc->ovl[1].hEvent) {
245 + CloseHandle(npc->ovl[1].hEvent);
246 + npc->ovl[1].hEvent = 0;
247 }
248 return 0;
249 }
250
251 static void rpcrt4_conn_np_cancel_call(RpcConnection *Connection)
252 @@ -579,11 +601,11 @@
253 /* open and count connections */
254 *count = 1;
255 conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common);
256 while (conn) {
257 rpcrt4_conn_listen_pipe(conn);
258 - if (conn->ovl.hEvent)
259 + if (conn->ovl[0].hEvent)
260 (*count)++;
261 conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
262 }
263
264 /* make array of connections */
265 @@ -600,11 +622,11 @@
266
267 objs[0] = npps->mgr_event;
268 *count = 1;
269 conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common);
270 while (conn) {
271 - if ((objs[*count] = conn->ovl.hEvent))
272 + if ((objs[*count] = conn->ovl[0].hEvent))
273 (*count)++;
274 conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
275 }
276 LeaveCriticalSection(&protseq->cs);
277 return objs;
278 @@ -647,11 +669,11 @@
279 b_handle = objs[res - WAIT_OBJECT_0];
280 /* find which connection got a RPC */
281 EnterCriticalSection(&protseq->cs);
282 conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common);
283 while (conn) {
284 - if (b_handle == conn->ovl.hEvent) break;
285 + if (b_handle == conn->ovl[0].hEvent) break;
286 conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
287 }
288 cconn = NULL;
289 if (conn)
290 RPCRT4_SpawnConnection(&cconn, &conn->common);