:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[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  */
35 VOID STDCALL
36 NiClosePort (PVOID      ObjectBody, ULONG       HandleCount)
37 {
38   PEPORT Port = (PEPORT)ObjectBody;
39   LPC_MESSAGE Message;
40   
41   /*
42    * If the client has just closed its handle then tell the server what
43    * happened and disconnect this port.
44    */
45   if (HandleCount == 0 && Port->State == EPORT_CONNECTED_CLIENT && 
46       ObGetObjectPointerCount(Port) == 2)
47     {
48       Message.MessageSize = sizeof(LPC_MESSAGE);
49       Message.DataSize = 0;
50       EiReplyOrRequestPort (Port->OtherPort,
51                             &Message,
52                             LPC_PORT_CLOSED,
53                             Port);
54       Port->OtherPort->OtherPort = NULL;
55       Port->OtherPort->State = EPORT_DISCONNECTED;
56       KeReleaseSemaphore( &Port->OtherPort->Semaphore,
57                           IO_NO_INCREMENT,
58                           1,
59                           FALSE );
60       ObDereferenceObject (Port);
61     }
62
63   /*
64    * If the server has closed all of its handles then disconnect the port,
65    * don't actually notify the client until it attempts an operation.
66    */
67   if (HandleCount == 0 && Port->State == EPORT_CONNECTED_SERVER && 
68       ObGetObjectPointerCount(Port) == 2)
69     {
70         Port->OtherPort->OtherPort = NULL;
71         Port->OtherPort->State = EPORT_DISCONNECTED;
72         ObDereferenceObject(Port->OtherPort);
73      }
74 }
75
76
77 /**********************************************************************
78  * NAME
79  *
80  * DESCRIPTION
81  *
82  * ARGUMENTS
83  *
84  * RETURN VALUE
85  *
86  * REVISIONS
87  *
88  */
89 VOID STDCALL
90 NiDeletePort (PVOID     ObjectBody)
91 {
92    //   PEPORT Port = (PEPORT)ObjectBody;
93    
94    //   DPRINT1("Deleting port %x\n", Port);
95 }
96
97
98 /* EOF */