- return r;
-@@ -358,9 +425,9 @@ static void rpcrt4_conn_np_handoff(RpcCo
- * to the child, then reopen the server binding to continue listening */
-
- new_npc->pipe = old_npc->pipe;
-- new_npc->listen_thread = old_npc->listen_thread;
-+ new_npc->ovl = old_npc->ovl;
- old_npc->pipe = 0;
-- old_npc->listen_thread = 0;
-+ memset(&old_npc->ovl, 0, sizeof(old_npc->ovl));
- old_npc->listening = FALSE;
- }
-
-@@ -444,20 +511,29 @@ static int rpcrt4_conn_np_read(RpcConnec
- void *buffer, unsigned int count)
- {
- RpcConnection_np *npc = (RpcConnection_np *) Connection;
-- IO_STATUS_BLOCK io_status;
- char *buf = buffer;
-+ BOOL ret = TRUE;
- unsigned int bytes_left = count;
-- NTSTATUS status;
-+ OVERLAPPED ovl;
-+
-+ ZeroMemory(&ovl, sizeof(ovl));
-+ ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
-
- while (bytes_left)
- {
-- status = NtReadFile(npc->pipe, NULL, NULL, NULL, &io_status, buf, bytes_left, NULL, NULL);
-- if (status && status != STATUS_BUFFER_OVERFLOW)
-- return -1;
-- bytes_left -= io_status.Information;
-- buf += io_status.Information;
-+ DWORD bytes_read;
-+ ret = ReadFile(npc->pipe, buf, bytes_left, &bytes_read, &ovl);
-+ if (!ret && GetLastError() == ERROR_IO_PENDING)
-+ ret = GetOverlappedResult(npc->pipe, &ovl, &bytes_read, TRUE);
-+ if (!ret && GetLastError() == ERROR_MORE_DATA)
-+ ret = TRUE;
-+ if (!ret || !bytes_read)
-+ break;
-+ bytes_left -= bytes_read;
-+ buf += bytes_read;
- }
-- return count;
-+ CloseHandle(ovl.hEvent);
-+ return ret ? count : -1;
- }
-
- static int rpcrt4_conn_np_write(RpcConnection *Connection,
-@@ -467,16 +543,23 @@ static int rpcrt4_conn_np_write(RpcConne
- const char *buf = buffer;
- BOOL ret = TRUE;
- unsigned int bytes_left = count;
-+ OVERLAPPED ovl;
-+
-+ ZeroMemory(&ovl, sizeof(ovl));
-+ ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
-
- while (bytes_left)
- {
- DWORD bytes_written;
-- ret = WriteFile(npc->pipe, buf, bytes_left, &bytes_written, NULL);
-+ ret = WriteFile(npc->pipe, buf, bytes_left, &bytes_written, &ovl);
-+ if (!ret && GetLastError() == ERROR_IO_PENDING)
-+ ret = GetOverlappedResult(npc->pipe, &ovl, &bytes_written, TRUE);
- if (!ret || !bytes_written)
- break;
- bytes_left -= bytes_written;
- buf += bytes_written;
- }
-+ CloseHandle(ovl.hEvent);
- return ret ? count : -1;
- }
-
-@@ -488,9 +571,9 @@ static int rpcrt4_conn_np_close(RpcConne
- CloseHandle(npc->pipe);
- npc->pipe = 0;
- }
-- if (npc->listen_thread) {
-- CloseHandle(npc->listen_thread);
-- npc->listen_thread = 0;
-+ if (npc->ovl.hEvent) {
-+ CloseHandle(npc->ovl.hEvent);
-+ npc->ovl.hEvent = 0;
- }
- return 0;
- }
-@@ -694,7 +777,7 @@ static void *rpcrt4_protseq_np_get_wait_
- conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common);
- while (conn) {
- rpcrt4_conn_listen_pipe(conn);
-- if (conn->listen_thread)
-+ if (conn->ovl.hEvent)
- (*count)++;
- conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
+@@ -286,7 +317,7 @@ static RPC_STATUS rpcrt4_protseq_ncacn_n
+ if (r != RPC_S_OK)
+ return r;
+
+- ((RpcConnection_np*)Connection)->listen_pipe = ncacn_pipe_name(Connection->Endpoint);
++ ((RpcConnection_np*)Connection)->listen_pipe = ncacn_pipe_name(NULL, Connection->Endpoint);
+ r = rpcrt4_conn_create_pipe(Connection);
+
+ EnterCriticalSection(&protseq->cs);
+@@ -337,7 +368,7 @@ static RPC_STATUS rpcrt4_ncacn_np_is_ser
+ char *pipe_name;
+ RPC_STATUS status;
+
+- pipe_name = ncacn_pipe_name(endpoint);
++ pipe_name = ncacn_pipe_name(NULL, endpoint);
+ status = is_pipe_listening(pipe_name);
+ I_RpcFree(pipe_name);
+ return status;
+@@ -395,10 +426,14 @@ static int rpcrt4_conn_np_read(RpcConnec
+ if (connection->read_closed)
+ {
+ IO_STATUS_BLOCK io_status;
++#ifdef __REACTOS__ /* FIXME: We should also cancel I/O for other threads */
++ NtCancelIoFile(connection->pipe, &io_status);
++#else
+ NtCancelIoFileEx(connection->pipe, &connection->io_status, &io_status);
++#endif
+ }
+ WaitForSingleObject(event, INFINITE);
+- status = connection->io_status.Status;
++ status = connection->io_status.u.Status;