TODO: ...npecho_*3
authorStefan Metzmacher <metze@samba.org>
Tue, 10 Feb 2009 10:56:43 +0000 (11:56 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 22 Apr 2013 09:12:56 +0000 (11:12 +0200)
metze

testprogs/win32/npecho/GNUmakefile
testprogs/win32/npecho/npecho_client3.c [new file with mode: 0755]
testprogs/win32/npecho/npecho_server3.c [new file with mode: 0755]

index 5b4f976949f07cf12c5a123ef9d8c2060a2d2e23..81e9c31c8f400b4a2a5e7684dd2937f799f8e36c 100755 (executable)
@@ -6,7 +6,9 @@ NPECHO = npecho_client.exe
 
 NPECHO2 = npecho_client2.exe npecho_server2.exe
 
-all: $(NPECHO) $(NPECHO2)
+NPECHO3 = npecho_client3.exe npecho_server3.exe
+
+all: $(NPECHO) $(NPECHO2) $(NPECHO3)
 
 MINGW_CC = i586-mingw32msvc-cc
 CC = $(MINGW_CC)
diff --git a/testprogs/win32/npecho/npecho_client3.c b/testprogs/win32/npecho/npecho_client3.c
new file mode 100755 (executable)
index 0000000..113ee7e
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Simple Named Pipe Client
+ * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+ * (C) 2009 Stefan Metzmacher <metze@samba.org>
+ * Published to the public domain
+ */
+
+#include <windows.h>
+#include <stdio.h>
+
+#define ECHODATA "Black Dog"
+
+int main(int argc, char *argv[])
+{
+       HANDLE h;
+       DWORD numread = 0;
+       char *outbuffer = malloc(sizeof(ECHODATA)*2);
+       BOOL small_reads = FALSE;
+       DWORD state = 0;
+       DWORD flags = 0;
+       char *inbuf = strdup(ECHODATA);
+       DWORD large = 0x10000;
+       char *largebuf = malloc(large);
+       memset(largebuf, 0x0, large);
+
+       if (argc == 1) {
+               goto usage;
+       } else if (argc >= 3) {
+               if (strcmp(argv[2], "large") == 0) {
+                       small_reads = FALSE;
+               } else if (strcmp(argv[2], "small") == 0) {
+                       small_reads = TRUE;
+               } else {
+                       goto usage;
+               }
+       }
+
+       h = CreateFile(argv[1], GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+       if (h == INVALID_HANDLE_VALUE) {
+               printf("Error opening: %d\n", GetLastError());
+               return -1;
+       }
+
+       GetNamedPipeHandleState(h, &state, NULL, NULL, NULL, NULL, 0);
+
+       if (state & PIPE_READMODE_MESSAGE) {
+               printf("message read mode\n");
+       } else {
+               printf("byte read mode\n");
+       }
+#if 0
+       if (!WriteFile(h, inbuf, sizeof(ECHODATA), &numread, NULL)) {
+               printf("WriteFile failed: %d!\n", GetLastError());
+               return -1;
+       }
+#endif
+#if 1
+       if (!TransactNamedPipe(h, largebuf, large, outbuffer, sizeof(ECHODATA), &numread, NULL)) {
+               printf("TransactNamedPipe failed: %d!\n", GetLastError());
+//             return -1;
+       }
+#endif
+#if 0
+       if (!TransactNamedPipe(h, inbuf, sizeof(ECHODATA), outbuffer, sizeof(ECHODATA), &numread, NULL)) {
+               printf("TransactNamedPipe failed: %d!\n", GetLastError());
+//             return -1;
+       }
+#endif
+#if 0
+       if (!ReadFile(h, outbuffer, sizeof(ECHODATA)*2, &numread, NULL)) {
+               printf("Error reading: %d\n", GetLastError());
+               return -1;
+       }
+#endif
+#if 0
+       if (!WriteFile(h, inbuf, sizeof(ECHODATA), &numread, NULL)) {
+               printf("WriteFile failed: %d!\n", GetLastError());
+               return -1;
+       }
+
+       if (!TransactNamedPipe(h, inbuf, sizeof(ECHODATA), outbuffer, sizeof(ECHODATA), &numread, NULL)) {
+               printf("TransactNamedPipe failed: %d!\n", GetLastError());
+               return -1;
+       }
+
+       if (!ReadFile(h, outbuffer, sizeof(ECHODATA)*2, &numread, NULL)) {
+               printf("Error reading: %d\n", GetLastError());
+               return -1;
+       }
+#endif
+       return 0;
+usage:
+       printf("Usage: %s pipename [read]\n", argv[0]);
+       printf("  Where pipename is something like \\\\servername\\NPECHO\n");
+       printf("  Where read is something 'large' or 'small'\n");
+       return -1;
+}
diff --git a/testprogs/win32/npecho/npecho_server3.c b/testprogs/win32/npecho/npecho_server3.c
new file mode 100755 (executable)
index 0000000..7b21e2b
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Simple Named Pipe Client
+ * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+ * (C) 2009 Stefan Metzmacher <metze@samba.org>
+ * Published to the public domain
+ */
+
+#include <windows.h>
+#include <stdio.h>
+
+#define ECHODATA "Black Dog"
+
+int main(int argc, char *argv[])
+{
+       HANDLE h;
+       DWORD numread = 0;
+       char *outbuffer = malloc(sizeof(ECHODATA)*2);
+       BOOL msgmode = FALSE;
+       DWORD type = 0;
+
+       if (argc == 1) {
+               goto usage;
+       } else if (argc >= 3) {
+               if (strcmp(argv[2], "byte") == 0) {
+                       msgmode = FALSE;
+               } else if (strcmp(argv[2], "message") == 0) {
+                       msgmode = TRUE;
+               } else {
+                       goto usage;
+               }
+       }
+
+       if (msgmode == TRUE) {
+               printf("using message mode\n");
+               type = PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT;
+       } else {
+               printf("using byte mode\n");
+               type = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT;
+       }
+
+       h = CreateNamedPipe(argv[1],
+                           PIPE_ACCESS_DUPLEX,
+                           type,
+                           PIPE_UNLIMITED_INSTANCES,
+                           1024,
+                           1024,
+                           0,
+                           NULL);
+       if (h == INVALID_HANDLE_VALUE) {
+               printf("Error opening: %d\n", GetLastError());
+               return -1;
+       }
+
+       ConnectNamedPipe(h, NULL);
+
+#if 0
+       if (!ReadFile(h, outbuffer, sizeof(ECHODATA)/2, &numread, NULL)) {
+               printf("Error reading: %d\n", GetLastError());
+               //return -1;
+       }
+#endif
+       if (!ReadFile(h, outbuffer, sizeof(ECHODATA), &numread, NULL)) {
+               printf("Error writing: %d\n", GetLastError());
+               //return -1;
+       }
+#if 0
+       if (!ReadFile(h, outbuffer+sizeof(ECHODATA), sizeof(ECHODATA), &numread, NULL)) {
+               printf("Error writing: %d\n", GetLastError());
+               return -1;
+       }
+#endif
+       if (!WriteFile(h, outbuffer, sizeof(ECHODATA)*2, &numread, NULL)) {
+               printf("Error writing: %d\n", GetLastError());
+               return -1;
+       }
+#if 0
+       if (!WriteFile(h, outbuffer, sizeof(ECHODATA), &numread, NULL)) {
+               printf("Error writing: %d\n", GetLastError());
+               return -1;
+       }
+#endif
+       FlushFileBuffers(h);
+       DisconnectNamedPipe(h);
+       CloseHandle(h);
+
+       return 0;
+usage:
+       printf("Usage: %s pipename [mode]\n", argv[0]);
+       printf("  Where pipename is something like \\\\servername\\PIPE\\NPECHO\n");
+       printf("  Where mode is 'byte' or 'message'\n");
+       return -1;
+}