3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/lpc/close.c
6 * PURPOSE: Communication mechanism
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
11 /* INCLUDES *****************************************************************/
15 #include <internal/debug.h>
17 /* FUNCTIONS *****************************************************************/
19 /**********************************************************************
31 LpcpClosePort (IN PEPROCESS Process OPTIONAL
,
33 IN ACCESS_MASK GrantedAccess
,
35 IN ULONG SystemHandleCount
)
37 PEPORT Port
= (PEPORT
)ObjectBody
;
40 /* FIXME Race conditions here! */
42 DPRINT("NiClosePort 0x%p OtherPort 0x%p State %d\n", Port
, Port
->OtherPort
, Port
->State
);
45 * If the client has just closed its handle then tell the server what
46 * happened and disconnect this port.
48 if (HandleCount
== 1 && Port
->State
== EPORT_CONNECTED_CLIENT
)
50 DPRINT("Informing server\n");
51 Message
.u1
.s1
.TotalLength
= sizeof(PORT_MESSAGE
);
52 Message
.u1
.s1
.DataLength
= 0;
53 EiReplyOrRequestPort (Port
->OtherPort
,
57 Port
->OtherPort
->OtherPort
= NULL
;
58 Port
->OtherPort
->State
= EPORT_DISCONNECTED
;
59 KeReleaseSemaphore( &Port
->OtherPort
->Semaphore
,
63 ObDereferenceObject (Port
);
67 * If the server has closed all of its handles then disconnect the port,
68 * don't actually notify the client until it attempts an operation.
70 if (HandleCount
== 1 && Port
->State
== EPORT_CONNECTED_SERVER
)
72 DPRINT("Cleaning up server\n");
73 Port
->OtherPort
->OtherPort
= NULL
;
74 Port
->OtherPort
->State
= EPORT_DISCONNECTED
;
75 ObDereferenceObject(Port
->OtherPort
);
80 /**********************************************************************
92 LpcpDeletePort (PVOID ObjectBody
)
95 PQUEUEDMESSAGE Message
;
97 PEPORT Port
= (PEPORT
)ObjectBody
;
99 DPRINT("Deleting port %x\n", Port
);
101 /* Free all waiting messages */
102 while (!IsListEmpty(&Port
->QueueListHead
))
104 Entry
= RemoveHeadList(&Port
->QueueListHead
);
105 Message
= CONTAINING_RECORD (Entry
, QUEUEDMESSAGE
, QueueListEntry
);
109 while (!IsListEmpty(&Port
->ConnectQueueListHead
))
111 Entry
= RemoveHeadList(&Port
->ConnectQueueListHead
);
112 Message
= CONTAINING_RECORD (Entry
, QUEUEDMESSAGE
, QueueListEntry
);