From 20037ec24c7bc00cb2fe64a16560ac6467e29ee0 Mon Sep 17 00:00:00 2001 From: Emanuele Aliberti Date: Sun, 24 Feb 2002 17:44:22 +0000 Subject: [PATCH] Modified demo LPC server and client with verbose output. svn path=/trunk/; revision=2646 --- reactos/apps/tests/lpc/lpcclt.c | 41 +++++++++--- reactos/apps/tests/lpc/lpcsrv.c | 111 +++++++++++++++++++------------ reactos/apps/tests/lpc/lpctest.h | 5 ++ 3 files changed, 105 insertions(+), 52 deletions(-) create mode 100644 reactos/apps/tests/lpc/lpctest.h diff --git a/reactos/apps/tests/lpc/lpcclt.c b/reactos/apps/tests/lpc/lpcclt.c index 4958efb3924..0df32a0b3fe 100644 --- a/reactos/apps/tests/lpc/lpcclt.c +++ b/reactos/apps/tests/lpc/lpcclt.c @@ -1,4 +1,4 @@ -/* $Id: lpcclt.c,v 1.7 2000/06/29 23:35:09 dwelch Exp $ +/* $Id: lpcclt.c,v 1.8 2002/02/24 17:44:22 ea Exp $ * * DESCRIPTION: Simple LPC Client * PROGRAMMER: David Welch @@ -11,6 +11,9 @@ #include #include +#include "lpctest.h" + +const char * MyName = "LPC-CLI"; HANDLE OutputHandle; HANDLE InputHandle; @@ -32,17 +35,20 @@ int main(int argc, char* argv[]) NTSTATUS Status; HANDLE PortHandle; LPC_MAX_MESSAGE Request; - ULONG ConnectInfoLength; + ULONG ConnectInfo; + ULONG ConnectInfoLength = 0; + SECURITY_QUALITY_OF_SERVICE Sqos; - printf("(lpcclt.exe) Lpc client\n"); + printf("%s: Lpc test client\n", MyName); - RtlInitUnicodeString(&PortName, L"\\TestPort"); + RtlInitUnicodeString(&PortName, TEST_PORT_NAME_U); - printf("(lpcclt.exe) Connecting to port \"\\TestPort\"\n"); + printf("%s: Connecting to port \"%s\"...\n", MyName, TEST_PORT_NAME); ConnectInfoLength = 0; + ZeroMemory (& Sqos, sizeof Sqos); Status = NtConnectPort(&PortHandle, &PortName, - NULL, + & Sqos, 0, 0, 0, @@ -50,26 +56,39 @@ int main(int argc, char* argv[]) &ConnectInfoLength); if (!NT_SUCCESS(Status)) { - printf("(lpcclt.exe) Failed to connect (Status = 0x%08X)\n", Status); + printf("%s: NtConnectPort() failed with status = 0x%08X.\n", MyName, Status); return EXIT_FAILURE; } - + + printf("%s: Connected to \"%s\" with anonymous port 0x%x.\n", MyName, TEST_PORT_NAME, PortHandle); + + ZeroMemory(& Request, sizeof Request); strcpy(Request.Data, GetCommandLineA()); Request.Header.DataSize = strlen(Request.Data); Request.Header.MessageSize = sizeof(LPC_MESSAGE_HEADER) + Request.Header.DataSize; - printf("(lpcclt.exe) Sending message \"%s\"\n", + printf("%s: Sending to port 0x%x message \"%s\"...\n", + MyName, + PortHandle, (char *) Request.Data); Status = NtRequestPort(PortHandle, &Request.Header); if (!NT_SUCCESS(Status)) { - printf("(lpcclt.exe) Failed to send request (Status = 0x%8X)\n", + printf("%s: NtRequestPort(0x%x) failed with status = 0x%8X.\n", + MyName, + PortHandle, Status); return EXIT_FAILURE; } - printf("(lpcclt.exe) Succeeded\n"); + printf("%s: Sending datagram to port 0x%x succeeded.\n", MyName, PortHandle); + + Sleep(2000); + + printf("%s: Disconnecting...", MyName); + NtClose (PortHandle); + return EXIT_SUCCESS; } diff --git a/reactos/apps/tests/lpc/lpcsrv.c b/reactos/apps/tests/lpc/lpcsrv.c index 2bac4c6e07a..b816ceddc3a 100644 --- a/reactos/apps/tests/lpc/lpcsrv.c +++ b/reactos/apps/tests/lpc/lpcsrv.c @@ -1,4 +1,4 @@ -/* $Id: lpcsrv.c,v 1.7 2000/06/29 23:35:10 dwelch Exp $ +/* $Id: lpcsrv.c,v 1.8 2002/02/24 17:44:22 ea Exp $ * * DESCRIPTION: Simple LPC Server * PROGRAMMER: David Welch @@ -11,6 +11,10 @@ #include #include +#include "lpctest.h" + +static const char * MyName = "LPC-SRV"; + HANDLE OutputHandle; HANDLE InputHandle; @@ -35,16 +39,16 @@ int main(int argc, char* argv[]) HANDLE PortHandle; LPC_MAX_MESSAGE ConnectMsg; - printf("(lpcsrv.exe) Lpc test server\n"); + printf("%s: Lpc test server\n", MyName); - RtlInitUnicodeString(&PortName, L"\\TestPort"); + RtlInitUnicodeString(&PortName, TEST_PORT_NAME_U); InitializeObjectAttributes(&ObjectAttributes, &PortName, 0, NULL, NULL); - printf("(lpcsrv.exe) Creating port\n"); + printf("%s: Creating port \"%s\"...\n", MyName, TEST_PORT_NAME); Status = NtCreatePort(&NamedPortHandle, &ObjectAttributes, 0, @@ -52,58 +56,83 @@ int main(int argc, char* argv[]) 0); if (!NT_SUCCESS(Status)) { - printf("(lpcsrv.exe) Failed to create port (Status = 0x%08lX)\n", Status); + printf("%s: NtCreatePort() failed with status = 0x%08lX.\n", MyName, Status); return EXIT_FAILURE; } + printf("%s: Port \"%s\" created (0x%x).\n\n", MyName, TEST_PORT_NAME, NamedPortHandle); - - printf("(lpcsrv.exe) Listening for connections\n"); - Status = NtListenPort(NamedPortHandle, + for (;;) + { + printf("%s: Listening for connections requests on port 0x%x...\n", MyName, NamedPortHandle); + Status = NtListenPort(NamedPortHandle, &ConnectMsg.Header); - if (!NT_SUCCESS(Status)) - { - printf("(lpcsrv.exe) Failed to listen for connections (Status = 0x%08lX)\n", Status); - return EXIT_FAILURE; - } + if (!NT_SUCCESS(Status)) + { + printf("%s: NtListenPort() failed with status = 0x%08lX.\n", MyName, Status); + return EXIT_FAILURE; + } + + printf("%s: Received connection request 0x%08x on port 0x%x.\n", MyName, + ConnectMsg.Header.MessageId, NamedPortHandle); + printf("%s: Request from: PID=%x, TID=%x.\n", MyName, + ConnectMsg.Header.Cid.UniqueProcess, ConnectMsg.Header.Cid.UniqueThread); - printf("(lpcsrv.exe) Accepting connections\n"); - Status = NtAcceptConnectPort(&PortHandle, + printf("%s: Accepting connection request 0x%08x...\n", MyName, + ConnectMsg.Header.MessageId); + Status = NtAcceptConnectPort(&PortHandle, NamedPortHandle, - NULL, - 1, + & ConnectMsg.Header, + TRUE, 0, NULL); - if (!NT_SUCCESS(Status)) - { - printf("(lpcsrv.exe) Failed to accept connection (Status = 0x%08lX)\n", Status); - return EXIT_FAILURE; - } + if (!NT_SUCCESS(Status)) + { + printf("%s: NtAcceptConnectPort() failed with status = 0x%08lX.\n", MyName, Status); + return EXIT_FAILURE; + } + printf("%s: Connection request 0x%08x accepted as port 0x%x.\n", MyName, + ConnectMsg.Header.MessageId, PortHandle); - printf("(lpcsrv.exe) Completing connection\n"); - Status = NtCompleteConnectPort(PortHandle); - if (!NT_SUCCESS(Status)) - { - printf("(lpcsrv.exe) Failed to complete connection (Status = 0x%08lX)\n", Status); - return EXIT_FAILURE; - } - - for(;;) - { - LPC_MAX_MESSAGE Request; + printf("%s: Completing connection for port 0x%x (0x%08x).\n", MyName, + PortHandle, ConnectMsg.Header.MessageId); + Status = NtCompleteConnectPort(PortHandle); + if (!NT_SUCCESS(Status)) + { + printf("%s: NtCompleteConnectPort() failed with status = 0x%08lX.\n", MyName, Status); + return EXIT_FAILURE; + } + + printf("%s: Entering server loop for port 0x%x...\n", MyName, PortHandle); + for(;;) + { + LPC_MAX_MESSAGE Request; - Status = NtReplyWaitReceivePort(PortHandle, + Status = NtReplyWaitReceivePort(PortHandle, 0, NULL, &Request.Header); - if (!NT_SUCCESS(Status)) - { - printf("(lpcsrv.exe) Failed to receive request (Status = 0x%08lX)\n", Status); + if (!NT_SUCCESS(Status)) + { + printf("%s: NtReplyWaitReceivePort() failed with status = 0x%08lX.\n", MyName, Status); return EXIT_FAILURE; - } - - printf("(lpcsrv.exe) Message contents are <%s>\n", + } + + if (LPC_DATAGRAM == PORT_MESSAGE_TYPE(Request)) + { + printf("%s: Datagram message contents are <%s>.\n", + MyName, Request.Data); - } + } + else + { + printf("%s: Message with type %d received on port 0x%x.\n", MyName, + PORT_MESSAGE_TYPE(Request), PortHandle); + NtClose(PortHandle); + printf("%s: Connected port 0x%x closed.\n\n", MyName, PortHandle); + break; + } + } + } return EXIT_SUCCESS; } diff --git a/reactos/apps/tests/lpc/lpctest.h b/reactos/apps/tests/lpc/lpctest.h new file mode 100644 index 00000000000..6e6520844e8 --- /dev/null +++ b/reactos/apps/tests/lpc/lpctest.h @@ -0,0 +1,5 @@ +#ifndef _LPCTEST_H +#define _LPCTEST_H +#define TEST_PORT_NAME "\\TestPort" +#define TEST_PORT_NAME_U L"\\TestPort" +#endif