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 (PVOID ObjectBody
, ULONG HandleCount
)
33 PEPORT Port
= (PEPORT
)ObjectBody
;
36 /* FIXME Race conditions here! */
38 DPRINT("NiClosePort 0x%p OtherPort 0x%p State %d\n", Port
, Port
->OtherPort
, Port
->State
);
41 * If the client has just closed its handle then tell the server what
42 * happened and disconnect this port.
44 if (HandleCount
== 1 && Port
->State
== EPORT_CONNECTED_CLIENT
)
46 DPRINT("Informing server\n");
47 Message
.u1
.s1
.TotalLength
= sizeof(PORT_MESSAGE
);
48 Message
.u1
.s1
.DataLength
= 0;
49 EiReplyOrRequestPort (Port
->OtherPort
,
53 Port
->OtherPort
->OtherPort
= NULL
;
54 Port
->OtherPort
->State
= EPORT_DISCONNECTED
;
55 KeReleaseSemaphore( &Port
->OtherPort
->Semaphore
,
59 ObDereferenceObject (Port
);
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.
66 if (HandleCount
== 1 && Port
->State
== EPORT_CONNECTED_SERVER
)
68 DPRINT("Cleaning up server\n");
69 Port
->OtherPort
->OtherPort
= NULL
;
70 Port
->OtherPort
->State
= EPORT_DISCONNECTED
;
71 ObDereferenceObject(Port
->OtherPort
);
76 /**********************************************************************
88 LpcpDeletePort (PVOID ObjectBody
)
91 PQUEUEDMESSAGE Message
;
93 PEPORT Port
= (PEPORT
)ObjectBody
;
95 DPRINT("Deleting port %x\n", Port
);
97 /* Free all waiting messages */
98 while (!IsListEmpty(&Port
->QueueListHead
))
100 Entry
= RemoveHeadList(&Port
->QueueListHead
);
101 Message
= CONTAINING_RECORD (Entry
, QUEUEDMESSAGE
, QueueListEntry
);
105 while (!IsListEmpty(&Port
->ConnectQueueListHead
))
107 Entry
= RemoveHeadList(&Port
->ConnectQueueListHead
);
108 Message
= CONTAINING_RECORD (Entry
, QUEUEDMESSAGE
, QueueListEntry
);