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