merge trunk rev : 25663 and 25664 to 0.3.1 branch - update freetype, take care of...
[reactos.git] / reactos / 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 *
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #define NDEBUG
15 #include <internal/debug.h>
16
17 /* FUNCTIONS *****************************************************************/
18
19 VOID
20 NTAPI
21 LpcExitThread(IN PETHREAD Thread)
22 {
23 /* Make sure that the Reply Chain is empty */
24 if (!IsListEmpty(&Thread->LpcReplyChain))
25 {
26 /* It's not, remove the entry */
27 RemoveEntryList(&Thread->LpcReplyChain);
28 }
29
30 /* Set the thread in exit mode */
31 Thread->LpcExitThreadCalled = TRUE;
32 Thread->LpcReplyMessageId = 0;
33
34 /* FIXME: Reply to the LpcReplyMessage */
35 }
36
37 /**********************************************************************
38 * NAME
39 *
40 * DESCRIPTION
41 *
42 * ARGUMENTS
43 *
44 * RETURN VALUE
45 *
46 * REVISIONS
47 */
48 VOID STDCALL
49 LpcpClosePort (IN PEPROCESS Process OPTIONAL,
50 IN PVOID ObjectBody,
51 IN ACCESS_MASK GrantedAccess,
52 IN ULONG HandleCount,
53 IN ULONG SystemHandleCount)
54 {
55 PEPORT Port = (PEPORT)ObjectBody;
56 PORT_MESSAGE Message;
57
58 /* FIXME Race conditions here! */
59
60 /*
61 * If the client has just closed its handle then tell the server what
62 * happened and disconnect this port.
63 */
64 if (!(HandleCount)&& (Port->State == EPORT_CONNECTED_CLIENT))
65 {
66 DPRINT("Informing server\n");
67 Message.u1.s1.TotalLength = sizeof(PORT_MESSAGE);
68 Message.u1.s1.DataLength = 0;
69 EiReplyOrRequestPort (Port->OtherPort,
70 &Message,
71 LPC_PORT_CLOSED,
72 Port);
73 Port->OtherPort->OtherPort = NULL;
74 Port->OtherPort->State = EPORT_DISCONNECTED;
75 KeReleaseSemaphore( &Port->OtherPort->Semaphore,
76 IO_NO_INCREMENT,
77 1,
78 FALSE );
79 ObDereferenceObject (Port);
80 }
81
82 /*
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.
85 */
86 if (!(HandleCount)&& (Port->State == EPORT_CONNECTED_SERVER))
87 {
88 DPRINT("Cleaning up server\n");
89 Port->OtherPort->OtherPort = NULL;
90 Port->OtherPort->State = EPORT_DISCONNECTED;
91 ObDereferenceObject(Port->OtherPort);
92 }
93 }
94
95
96 /**********************************************************************
97 * NAME
98 *
99 * DESCRIPTION
100 *
101 * ARGUMENTS
102 *
103 * RETURN VALUE
104 *
105 * REVISIONS
106 */
107 VOID STDCALL
108 LpcpDeletePort (PVOID ObjectBody)
109 {
110 PLIST_ENTRY Entry;
111 PQUEUEDMESSAGE Message;
112
113 PEPORT Port = (PEPORT)ObjectBody;
114
115 DPRINT("Deleting port %x\n", Port);
116
117 /* Free all waiting messages */
118 while (!IsListEmpty(&Port->QueueListHead))
119 {
120 Entry = RemoveHeadList(&Port->QueueListHead);
121 Message = CONTAINING_RECORD (Entry, QUEUEDMESSAGE, QueueListEntry);
122 ExFreePool(Message);
123 }
124
125 while (!IsListEmpty(&Port->ConnectQueueListHead))
126 {
127 Entry = RemoveHeadList(&Port->ConnectQueueListHead);
128 Message = CONTAINING_RECORD (Entry, QUEUEDMESSAGE, QueueListEntry);
129 ExFreePool(Message);
130 }
131 }
132
133
134 /* EOF */