2004-08-15 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / reactos / ntoskrnl / lpc / complete.c
1 /* $Id: complete.c,v 1.12 2004/08/15 16:39:06 chorns 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 <ntoskrnl.h>
15 #define NDEBUG
16 #include <internal/debug.h>
17
18 /* FUNCTIONS *****************************************************************/
19
20 /***********************************************************************
21 * NAME EXPORTED
22 * NtCompleteConnectPort/1
23 *
24 * DESCRIPTION
25 * Wake up the client thread that issued the NtConnectPort call
26 * this server-side port was created for communicating with.
27 * To be used in LPC servers processes on reply ports only.
28 *
29 * ARGUMENTS
30 * hServerSideCommPort: a reply port handle returned by
31 * NtAcceptConnectPort.
32 *
33 * RETURN VALUE
34 * STATUS_SUCCESS or an error code from Ob.
35 */
36 NTSTATUS STDCALL
37 NtCompleteConnectPort (HANDLE hServerSideCommPort)
38 {
39 NTSTATUS Status;
40 PEPORT ReplyPort;
41
42 DPRINT("NtCompleteConnectPort(hServerSideCommPort %x)\n", hServerSideCommPort);
43
44 /*
45 * Ask Ob to translate the port handle to EPORT
46 */
47 Status = ObReferenceObjectByHandle (hServerSideCommPort,
48 PORT_ALL_ACCESS,
49 ExPortType,
50 UserMode,
51 (PVOID*)&ReplyPort,
52 NULL);
53 if (!NT_SUCCESS(Status))
54 {
55 return (Status);
56 }
57 /*
58 * Verify EPORT type is a server-side reply port;
59 * otherwise tell the caller the port handle is not
60 * valid.
61 */
62 if (ReplyPort->Type != EPORT_TYPE_SERVER_COMM_PORT)
63 {
64 ObDereferenceObject (ReplyPort);
65 return STATUS_INVALID_PORT_HANDLE;
66 }
67
68 ReplyPort->State = EPORT_CONNECTED_SERVER;
69 /*
70 * Wake up the client thread that issued NtConnectPort.
71 */
72 KeReleaseSemaphore(&ReplyPort->OtherPort->Semaphore, IO_NO_INCREMENT, 1,
73 FALSE);
74 /*
75 * Tell Ob we are no more interested in ReplyPort
76 */
77 ObDereferenceObject (ReplyPort);
78
79 return (STATUS_SUCCESS);
80 }
81
82
83 /* EOF */