From 5438d7dad8d349f8fdc07a89870ddafb9c54a68f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 9 Feb 2009 11:54:34 +0100 Subject: testprogs/win32: add npecho_*2.c This exlores some details of message type named pipes. metze --- testprogs/win32/npecho/npecho_server2.c | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 testprogs/win32/npecho/npecho_server2.c (limited to 'testprogs/win32/npecho/npecho_server2.c') diff --git a/testprogs/win32/npecho/npecho_server2.c b/testprogs/win32/npecho/npecho_server2.c new file mode 100755 index 0000000000..72edb02004 --- /dev/null +++ b/testprogs/win32/npecho/npecho_server2.c @@ -0,0 +1,55 @@ +/* + * Simple Named Pipe Client + * (C) 2005 Jelmer Vernooij + * (C) 2009 Stefan Metzmacher + * Published to the public domain + */ + +#include +#include + +#define ECHODATA "Black Dog" + +int main(int argc, char *argv[]) +{ + HANDLE h; + DWORD numread = 0; + char *outbuffer = malloc(sizeof(ECHODATA)); + + if (argc == 1) { + printf("Usage: %s pipename\n", argv[0]); + printf(" Where pipename is something like \\\\servername\\NPECHO\n"); + return -1; + } + + h = CreateNamedPipe(argv[1], + PIPE_ACCESS_DUPLEX, + PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, + PIPE_UNLIMITED_INSTANCES, + 1024, + 1024, + 0, + NULL); + if (h == INVALID_HANDLE_VALUE) { + printf("Error opening: %d\n", GetLastError()); + return -1; + } + + ConnectNamedPipe(h, NULL); + + if (!WriteFile(h, ECHODATA, sizeof(ECHODATA), &numread, NULL)) { + printf("Error writing: %d\n", GetLastError()); + return -1; + } + + if (!WriteFile(h, ECHODATA, sizeof(ECHODATA), &numread, NULL)) { + printf("Error writing: %d\n", GetLastError()); + return -1; + } + + FlushFileBuffers(h); + DisconnectNamedPipe(h); + CloseHandle(h); + + return 0; +} -- cgit