update for HEAD-2003091401
[reactos.git] / ntoskrnl / lpc / listen.c
1 /* $Id$
2  * 
3  * COPYRIGHT:       See COPYING in the top level directory
4  * PROJECT:         ReactOS kernel
5  * FILE:            ntoskrnl/lpc/listen.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 <ddk/ntddk.h>
15 #include <internal/ob.h>
16 #include <internal/port.h>
17 #include <internal/dbg.h>
18
19 #define NDEBUG
20 #include <internal/debug.h>
21
22 /* FUNCTIONS *****************************************************************/
23
24 /**********************************************************************
25  * NAME                                                 EXPORTED
26  *      NtListenPort@8
27  *
28  * DESCRIPTION
29  *      Listen on a named port and wait for a connection attempt.
30  *
31  * ARGUMENTS
32  *      PortHandle      [IN] LPC port to listen on.
33  *
34  *      ConnectMsg      [IN] User provided storage for a
35  *                      possible connection request LPC message.
36  *
37  * RETURN VALUE
38  *      STATUS_SUCCESS if a connection request is received
39  *      successfully; otherwise an error code.
40  *
41  *      The buffer ConnectMessage is filled with the connection
42  *      request message queued by NtConnectPort() in PortHandle.
43  *
44  * NOTE
45  */
46 EXPORTED NTSTATUS STDCALL
47 NtListenPort (IN        HANDLE          PortHandle,
48               IN        PLPC_MESSAGE    ConnectMsg)
49 {
50   NTSTATUS      Status;
51   
52   /*
53    * Wait forever for a connection request.
54    */
55   for (;;)
56     {
57       Status = NtReplyWaitReceivePort(PortHandle,
58                                       NULL,
59                                       NULL,
60                                       ConnectMsg);
61       /*
62        * Accept only LPC_CONNECTION_REQUEST requests.
63        * Drop any other message.
64        */
65       if (!NT_SUCCESS(Status) || 
66           LPC_CONNECTION_REQUEST == ConnectMsg->MessageType)
67         {
68           DPRINT("Got message (type %x)\n", LPC_CONNECTION_REQUEST);
69           break;
70         }
71       DPRINT("Got message (type %x)\n", ConnectMsg->MessageType);
72     }
73   
74   return (Status);
75 }
76
77
78 /* EOF */