implemented sweeping of handle tables
[reactos.git] / reactos / ntoskrnl / lpc / close.c
index 1fd8d76..1091bfc 100644 (file)
@@ -1,12 +1,11 @@
 /* $Id$
- * 
+ *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/lpc/close.c
  * PURPOSE:         Communication mechanism
- * PROGRAMMER:      David Welch (welch@cwcom.net)
- * UPDATE HISTORY:
- *                  Created 22/05/98
+ *
+ * PROGRAMMERS:     David Welch (welch@cwcom.net)
  */
 
 /* INCLUDES *****************************************************************/
  * REVISIONS
  */
 VOID STDCALL
-NiClosePort (PVOID     ObjectBody, ULONG       HandleCount)
+LpcpClosePort (PVOID   ObjectBody, ULONG       HandleCount)
 {
   PEPORT Port = (PEPORT)ObjectBody;
-  LPC_MESSAGE Message;
+  PORT_MESSAGE Message;
 
   /* FIXME Race conditions here! */
 
@@ -42,12 +41,11 @@ NiClosePort (PVOID  ObjectBody, ULONG       HandleCount)
    * If the client has just closed its handle then tell the server what
    * happened and disconnect this port.
    */
-  if (HandleCount == 0 && Port->State == EPORT_CONNECTED_CLIENT && 
-      ObGetObjectPointerCount(Port) == 2)
+  if (HandleCount == 1 && Port->State == EPORT_CONNECTED_CLIENT)
     {
       DPRINT("Informing server\n");
-      Message.MessageSize = sizeof(LPC_MESSAGE);
-      Message.DataSize = 0;
+      Message.u1.s1.TotalLength = sizeof(PORT_MESSAGE);
+      Message.u1.s1.DataLength = 0;
       EiReplyOrRequestPort (Port->OtherPort,
                            &Message,
                            LPC_PORT_CLOSED,
@@ -65,8 +63,7 @@ NiClosePort (PVOID    ObjectBody, ULONG       HandleCount)
    * If the server has closed all of its handles then disconnect the port,
    * don't actually notify the client until it attempts an operation.
    */
-  if (HandleCount == 0 && Port->State == EPORT_CONNECTED_SERVER && 
-      ObGetObjectPointerCount(Port) == 1)
+  if (HandleCount == 1 && Port->State == EPORT_CONNECTED_SERVER)
     {
         DPRINT("Cleaning up server\n");
        Port->OtherPort->OtherPort = NULL;
@@ -88,11 +85,29 @@ NiClosePort (PVOID  ObjectBody, ULONG       HandleCount)
  * REVISIONS
  */
 VOID STDCALL
-NiDeletePort (PVOID    ObjectBody)
+LpcpDeletePort (PVOID  ObjectBody)
 {
-   //   PEPORT Port = (PEPORT)ObjectBody;
-   
-   //   DPRINT1("Deleting port %x\n", Port);
+   PLIST_ENTRY Entry;
+   PQUEUEDMESSAGE      Message;
+
+   PEPORT Port = (PEPORT)ObjectBody;
+
+   DPRINT("Deleting port %x\n", Port);
+
+   /* Free all waiting messages */
+   while (!IsListEmpty(&Port->QueueListHead))
+     {
+       Entry = RemoveHeadList(&Port->QueueListHead);
+       Message = CONTAINING_RECORD (Entry, QUEUEDMESSAGE, QueueListEntry);
+       ExFreePool(Message);
+     }
+
+   while (!IsListEmpty(&Port->ConnectQueueListHead))
+     {
+       Entry = RemoveHeadList(&Port->ConnectQueueListHead);
+       Message = CONTAINING_RECORD (Entry, QUEUEDMESSAGE, QueueListEntry);
+       ExFreePool(Message);
+     }
 }