1 /* $Id: lpcsrv.c 15091 2005-05-07 21:24:31Z sedwards $
3 * DESCRIPTION: Simple LPC Server
4 * PROGRAMMER: David Welch
7 #include <rosrtl/string.h>
16 static const char * MyName
= "LPC-SRV";
21 void debug_printf(char* fmt
, ...)
27 vsprintf(buffer
,fmt
,args
);
28 WriteConsoleA(OutputHandle
, buffer
, strlen(buffer
), NULL
, NULL
);
33 int main(int argc
, char* argv
[])
35 UNICODE_STRING PortName
= ROS_STRING_INITIALIZER(TEST_PORT_NAME_U
);
36 OBJECT_ATTRIBUTES ObjectAttributes
;
38 HANDLE NamedPortHandle
;
40 LPC_MAX_MESSAGE ConnectMsg
;
42 printf("%s: Lpc test server\n", MyName
);
44 InitializeObjectAttributes(&ObjectAttributes
,
50 printf("%s: Creating port \"%s\"...\n", MyName
, TEST_PORT_NAME
);
51 Status
= NtCreatePort(&NamedPortHandle
,
56 if (!NT_SUCCESS(Status
))
58 printf("%s: NtCreatePort() failed with status = 0x%08lX.\n", MyName
, Status
);
61 printf("%s: Port \"%s\" created (0x%x).\n\n", MyName
, TEST_PORT_NAME
, NamedPortHandle
);
65 printf("%s: Listening for connections requests on port 0x%x...\n", MyName
, NamedPortHandle
);
66 Status
= NtListenPort(NamedPortHandle
,
68 if (!NT_SUCCESS(Status
))
70 printf("%s: NtListenPort() failed with status = 0x%08lX.\n", MyName
, Status
);
74 printf("%s: Received connection request 0x%08x on port 0x%x.\n", MyName
,
75 ConnectMsg
.Header
.MessageId
, NamedPortHandle
);
76 printf("%s: Request from: PID=%x, TID=%x.\n", MyName
,
77 ConnectMsg
.Header
.ClientId
.UniqueProcess
, ConnectMsg
.Header
.ClientId
.UniqueThread
);
79 printf("%s: Accepting connection request 0x%08x...\n", MyName
,
80 ConnectMsg
.Header
.MessageId
);
81 Status
= NtAcceptConnectPort(&PortHandle
,
87 if (!NT_SUCCESS(Status
))
89 printf("%s: NtAcceptConnectPort() failed with status = 0x%08lX.\n", MyName
, Status
);
92 printf("%s: Connection request 0x%08x accepted as port 0x%x.\n", MyName
,
93 ConnectMsg
.Header
.MessageId
, PortHandle
);
95 printf("%s: Completing connection for port 0x%x (0x%08x).\n", MyName
,
96 PortHandle
, ConnectMsg
.Header
.MessageId
);
97 Status
= NtCompleteConnectPort(PortHandle
);
98 if (!NT_SUCCESS(Status
))
100 printf("%s: NtCompleteConnectPort() failed with status = 0x%08lX.\n", MyName
, Status
);
104 printf("%s: Entering server loop for port 0x%x...\n", MyName
, PortHandle
);
107 LPC_MAX_MESSAGE Request
;
109 Status
= NtReplyWaitReceivePort(PortHandle
,
113 if (!NT_SUCCESS(Status
))
115 printf("%s: NtReplyWaitReceivePort() failed with status = 0x%08lX.\n", MyName
, Status
);
119 if (LPC_DATAGRAM
== PORT_MESSAGE_TYPE(Request
))
121 printf("%s: Datagram message contents are <%s>.\n",
127 printf("%s: Message with type %d received on port 0x%x.\n", MyName
,
128 PORT_MESSAGE_TYPE(Request
), PortHandle
);
130 printf("%s: Connected port 0x%x closed.\n\n", MyName
, PortHandle
);