mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
Modified demo LPC server and client with verbose output.
svn path=/trunk/; revision=2646
This commit is contained in:
parent
0a549d94c9
commit
20037ec24c
3 changed files with 105 additions and 52 deletions
|
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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,41 +56,53 @@ 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");
|
||||
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);
|
||||
printf("%s: NtListenPort() failed with status = 0x%08lX.\n", MyName, Status);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("(lpcsrv.exe) Accepting connections\n");
|
||||
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("%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);
|
||||
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");
|
||||
printf("%s: Completing connection for port 0x%x (0x%08x).\n", MyName,
|
||||
PortHandle, ConnectMsg.Header.MessageId);
|
||||
Status = NtCompleteConnectPort(PortHandle);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
printf("(lpcsrv.exe) Failed to complete connection (Status = 0x%08lX)\n", 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;
|
||||
|
@ -97,13 +113,26 @@ int main(int argc, char* argv[])
|
|||
&Request.Header);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
printf("(lpcsrv.exe) Failed to receive request (Status = 0x%08lX)\n", 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;
|
||||
}
|
||||
|
||||
|
|
5
reactos/apps/tests/lpc/lpctest.h
Normal file
5
reactos/apps/tests/lpc/lpctest.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#ifndef _LPCTEST_H
|
||||
#define _LPCTEST_H
|
||||
#define TEST_PORT_NAME "\\TestPort"
|
||||
#define TEST_PORT_NAME_U L"\\TestPort"
|
||||
#endif
|
Loading…
Reference in a new issue