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