LPC: initial work on NT/ROS compatibility.
[reactos.git] / reactos / ntoskrnl / lpc / complete.c
1 /* $Id: complete.c,v 1.11 2004/02/02 23:48:42 ea Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/lpc/complete.c
6 * PURPOSE: Communication mechanism
7 * PROGRAMMER: David Welch (welch@cwcom.net)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 */
11
12 /* INCLUDES ******************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <internal/ob.h>
16 #include <internal/port.h>
17 #include <internal/dbg.h>
18
19 #define NDEBUG
20 #include <internal/debug.h>
21
22 /* FUNCTIONS *****************************************************************/
23
24 /***********************************************************************
25 * NAME EXPORTED
26 * NtCompleteConnectPort/1
27 *
28 * DESCRIPTION
29 * Wake up the client thread that issued the NtConnectPort call
30 * this server-side port was created for communicating with.
31 * To be used in LPC servers processes on reply ports only.
32 *
33 * ARGUMENTS
34 * hServerSideCommPort: a reply port handle returned by
35 * NtAcceptConnectPort.
36 *
37 * RETURN VALUE
38 * STATUS_SUCCESS or an error code from Ob.
39 */
40 NTSTATUS STDCALL
41 NtCompleteConnectPort (HANDLE hServerSideCommPort)
42 {
43 NTSTATUS Status;
44 PEPORT ReplyPort;
45
46 DPRINT("NtCompleteConnectPort(hServerSideCommPort %x)\n", hServerSideCommPort);
47
48 /*
49 * Ask Ob to translate the port handle to EPORT
50 */
51 Status = ObReferenceObjectByHandle (hServerSideCommPort,
52 PORT_ALL_ACCESS,
53 ExPortType,
54 UserMode,
55 (PVOID*)&ReplyPort,
56 NULL);
57 if (!NT_SUCCESS(Status))
58 {
59 return (Status);
60 }
61 /*
62 * Verify EPORT type is a server-side reply port;
63 * otherwise tell the caller the port handle is not
64 * valid.
65 */
66 if (ReplyPort->Type != EPORT_TYPE_SERVER_COMM_PORT)
67 {
68 ObDereferenceObject (ReplyPort);
69 return STATUS_INVALID_PORT_HANDLE;
70 }
71
72 ReplyPort->State = EPORT_CONNECTED_SERVER;
73 /*
74 * Wake up the client thread that issued NtConnectPort.
75 */
76 KeReleaseSemaphore(&ReplyPort->OtherPort->Semaphore, IO_NO_INCREMENT, 1,
77 FALSE);
78 /*
79 * Tell Ob we are no more interested in ReplyPort
80 */
81 ObDereferenceObject (ReplyPort);
82
83 return (STATUS_SUCCESS);
84 }
85
86
87 /* EOF */