78a95cbf3b50c309fc00a669f50e1f562593d39b
[reactos.git] / reactos / ntoskrnl / lpc / listen.c
1 /* $Id: listen.c,v 1.6 2003/07/10 20:42:53 royce Exp $
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 * @implemented
47 */
48 EXPORTED NTSTATUS STDCALL
49 NtListenPort (IN HANDLE PortHandle,
50 IN PLPC_MESSAGE ConnectMsg)
51 {
52 NTSTATUS Status;
53
54 /*
55 * Wait forever for a connection request.
56 */
57 for (;;)
58 {
59 Status = NtReplyWaitReceivePort(PortHandle,
60 NULL,
61 NULL,
62 ConnectMsg);
63 /*
64 * Accept only LPC_CONNECTION_REQUEST requests.
65 * Drop any other message.
66 */
67 if (!NT_SUCCESS(Status) ||
68 LPC_CONNECTION_REQUEST == ConnectMsg->MessageType)
69 {
70 DPRINT("Got message (type %x)\n", LPC_CONNECTION_REQUEST);
71 break;
72 }
73 DPRINT("Got message (type %x)\n", ConnectMsg->MessageType);
74 }
75
76 return (Status);
77 }
78
79
80 /* EOF */