forget update de.rc
[reactos.git] / reactos / ntoskrnl / lpc / complete.c
index 97c2d82..e14350d 100644 (file)
@@ -1,21 +1,16 @@
-/* $Id: complete.c,v 1.9 2003/07/11 01:23:15 royce Exp $
- * 
+/* $Id$
+ *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/lpc/complete.c
  * PURPOSE:         Communication mechanism
- * PROGRAMMER:      David Welch (welch@cwcom.net)
- * UPDATE HISTORY:
- *                  Created 22/05/98
+ *
+ * PROGRAMMERS:     David Welch (welch@cwcom.net)
  */
 
 /* INCLUDES ******************************************************************/
 
-#include <ddk/ntddk.h>
-#include <internal/ob.h>
-#include <internal/port.h>
-#include <internal/dbg.h>
-
+#include <ntoskrnl.h>
 #define NDEBUG
 #include <internal/debug.h>
 
 
 /***********************************************************************
  * NAME                                                        EXPORTED
- *     NtCompleteConnectPort@4
+ *     NtCompleteConnectPort/1
  *
+ * DESCRIPTION
+ *     Wake up the client thread that issued the NtConnectPort call
+ *     this server-side port was created for communicating with.
+ *     To be used in LPC servers processes on reply ports only.
+ *
+ * ARGUMENTS
+ *     hServerSideCommPort: a reply port handle returned by
+ *     NtAcceptConnectPort.
+ *
+ * RETURN VALUE
+ *     STATUS_SUCCESS or an error code from Ob.
  */
-EXPORTED NTSTATUS STDCALL
-NtCompleteConnectPort (HANDLE PortHandle)
+NTSTATUS STDCALL
+NtCompleteConnectPort (HANDLE hServerSideCommPort)
 {
   NTSTATUS     Status;
-  PEPORT               OurPort;
-  
-  DPRINT("NtCompleteConnectPort(PortHandle %x)\n", PortHandle);
-  
-  Status = ObReferenceObjectByHandle (PortHandle,
+  PEPORT       ReplyPort;
+
+  DPRINT("NtCompleteConnectPort(hServerSideCommPort %x)\n", hServerSideCommPort);
+
+  /*
+   * Ask Ob to translate the port handle to EPORT
+   */
+  Status = ObReferenceObjectByHandle (hServerSideCommPort,
                                      PORT_ALL_ACCESS,
-                                     ExPortType,
+                                     LpcPortObjectType,
                                      UserMode,
-                                     (PVOID*)&OurPort,
+                                     (PVOID*)&ReplyPort,
                                      NULL);
   if (!NT_SUCCESS(Status))
     {
       return (Status);
     }
-  
-  OurPort->State = EPORT_CONNECTED_SERVER;
-  
-  KeReleaseSemaphore(&OurPort->OtherPort->Semaphore, IO_NO_INCREMENT, 1, 
+  /*
+   * Verify EPORT type is a server-side reply port;
+   * otherwise tell the caller the port handle is not
+   * valid.
+   */
+  if (ReplyPort->Type != EPORT_TYPE_SERVER_COMM_PORT)
+    {
+       ObDereferenceObject (ReplyPort);
+       return STATUS_INVALID_PORT_HANDLE;
+    }
+
+  ReplyPort->State = EPORT_CONNECTED_SERVER;
+  /*
+   * Wake up the client thread that issued NtConnectPort.
+   */
+  KeReleaseSemaphore(&ReplyPort->OtherPort->Semaphore, IO_NO_INCREMENT, 1,
                     FALSE);
-   
-  ObDereferenceObject (OurPort);
-  
+  /*
+   * Tell Ob we are no more interested in ReplyPort
+   */
+  ObDereferenceObject (ReplyPort);
+
   return (STATUS_SUCCESS);
 }