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 *****************************************************************/
21 LpcExitThread(IN PETHREAD Thread
)
23 /* Make sure that the Reply Chain is empty */
24 if (!IsListEmpty(&Thread
->LpcReplyChain
))
26 /* It's not, remove the entry */
27 RemoveEntryList(&Thread
->LpcReplyChain
);
30 /* Set the thread in exit mode */
31 Thread
->LpcExitThreadCalled
= TRUE
;
32 Thread
->LpcReplyMessageId
= 0;
34 /* FIXME: Reply to the LpcReplyMessage */
37 /**********************************************************************
49 LpcpClosePort (IN PEPROCESS Process OPTIONAL
,
51 IN ACCESS_MASK GrantedAccess
,
53 IN ULONG SystemHandleCount
)
55 PEPORT Port
= (PEPORT
)ObjectBody
;
58 /* FIXME Race conditions here! */
61 * If the client has just closed its handle then tell the server what
62 * happened and disconnect this port.
64 if (!(HandleCount
)&& (Port
->State
== EPORT_CONNECTED_CLIENT
))
66 DPRINT("Informing server\n");
67 Message
.u1
.s1
.TotalLength
= sizeof(PORT_MESSAGE
);
68 Message
.u1
.s1
.DataLength
= 0;
69 EiReplyOrRequestPort (Port
->OtherPort
,
73 Port
->OtherPort
->OtherPort
= NULL
;
74 Port
->OtherPort
->State
= EPORT_DISCONNECTED
;
75 KeReleaseSemaphore( &Port
->OtherPort
->Semaphore
,
79 ObDereferenceObject (Port
);
83 * If the server has closed all of its handles then disconnect the port,
84 * don't actually notify the client until it attempts an operation.
86 if (!(HandleCount
)&& (Port
->State
== EPORT_CONNECTED_SERVER
))
88 DPRINT("Cleaning up server\n");
89 Port
->OtherPort
->OtherPort
= NULL
;
90 Port
->OtherPort
->State
= EPORT_DISCONNECTED
;
91 ObDereferenceObject(Port
->OtherPort
);
96 /**********************************************************************
108 LpcpDeletePort (PVOID ObjectBody
)
111 PQUEUEDMESSAGE Message
;
113 PEPORT Port
= (PEPORT
)ObjectBody
;
115 DPRINT("Deleting port %x\n", Port
);
117 /* Free all waiting messages */
118 while (!IsListEmpty(&Port
->QueueListHead
))
120 Entry
= RemoveHeadList(&Port
->QueueListHead
);
121 Message
= CONTAINING_RECORD (Entry
, QUEUEDMESSAGE
, QueueListEntry
);
125 while (!IsListEmpty(&Port
->ConnectQueueListHead
))
127 Entry
= RemoveHeadList(&Port
->ConnectQueueListHead
);
128 Message
= CONTAINING_RECORD (Entry
, QUEUEDMESSAGE
, QueueListEntry
);