d81ad4530932491c462e2646a2a8518c9f561a09
[reactos.git] / ntoskrnl / lpc / close.c
1 /* $Id$
2  * 
3  * COPYRIGHT:       See COPYING in the top level directory
4  * PROJECT:         ReactOS kernel
5  * FILE:            ntoskrnl/lpc/close.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/port.h>
16 #include <internal/dbg.h>
17
18 #define NDEBUG
19 #include <internal/debug.h>
20
21 /* FUNCTIONS *****************************************************************/
22
23 /**********************************************************************
24  * NAME
25  *
26  * DESCRIPTION
27  *
28  * ARGUMENTS
29  *
30  * RETURN VALUE
31  *
32  * REVISIONS
33  */
34 VOID STDCALL
35 NiClosePort (PVOID      ObjectBody, ULONG       HandleCount)
36 {
37   PEPORT Port = (PEPORT)ObjectBody;
38   LPC_MESSAGE Message;
39   
40   /*
41    * If the client has just closed its handle then tell the server what
42    * happened and disconnect this port.
43    */
44   if (HandleCount == 0 && Port->State == EPORT_CONNECTED_CLIENT && 
45       ObGetObjectPointerCount(Port) == 2)
46     {
47       Message.MessageSize = sizeof(LPC_MESSAGE);
48       Message.DataSize = 0;
49       EiReplyOrRequestPort (Port->OtherPort,
50                             &Message,
51                             LPC_PORT_CLOSED,
52                             Port);
53       Port->OtherPort->OtherPort = NULL;
54       Port->OtherPort->State = EPORT_DISCONNECTED;
55       KeReleaseSemaphore( &Port->OtherPort->Semaphore,
56                           IO_NO_INCREMENT,
57                           1,
58                           FALSE );
59       ObDereferenceObject (Port);
60     }
61
62   /*
63    * If the server has closed all of its handles then disconnect the port,
64    * don't actually notify the client until it attempts an operation.
65    */
66   if (HandleCount == 0 && Port->State == EPORT_CONNECTED_SERVER && 
67       ObGetObjectPointerCount(Port) == 2)
68     {
69         Port->OtherPort->OtherPort = NULL;
70         Port->OtherPort->State = EPORT_DISCONNECTED;
71         ObDereferenceObject(Port->OtherPort);
72      }
73 }
74
75
76 /**********************************************************************
77  * NAME
78  *
79  * DESCRIPTION
80  *
81  * ARGUMENTS
82  *
83  * RETURN VALUE
84  *
85  * REVISIONS
86  */
87 VOID STDCALL
88 NiDeletePort (PVOID     ObjectBody)
89 {
90    //   PEPORT Port = (PEPORT)ObjectBody;
91    
92    //   DPRINT1("Deleting port %x\n", Port);
93 }
94
95
96 /* EOF */