r6611: Add mailslot test program
authorJelmer Vernooij <jelmer@samba.org>
Wed, 4 May 2005 10:44:50 +0000 (10:44 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:30 +0000 (13:16 -0500)
testprogs/win32/testmailslot/Makefile [new file with mode: 0644]
testprogs/win32/testmailslot/testmailslot.c [new file with mode: 0644]

diff --git a/testprogs/win32/testmailslot/Makefile b/testprogs/win32/testmailslot/Makefile
new file mode 100644 (file)
index 0000000..e307654
--- /dev/null
@@ -0,0 +1,10 @@
+INCLUDES=-I 
+CFLAGS=$(INCLUDES) -Zi -nologo
+
+all: testmailslot.exe
+
+clean:
+       del *~ *.obj testmailslot.exe 
+
+testmailslot.exe: testmailslot.obj 
+       $(CC) $(CFLAGS) -o testmailslot.exe testmailslot.obj $(LIBS)
diff --git a/testprogs/win32/testmailslot/testmailslot.c b/testprogs/win32/testmailslot/testmailslot.c
new file mode 100644 (file)
index 0000000..b953636
--- /dev/null
@@ -0,0 +1,80 @@
+/*\r
+ * Very simple test application for mailslots\r
+ * (C) 2005 Jelmer Vernooij <jelmer@samba.org>\r
+ * Published to the public domain\r
+ */\r
+\r
+#include <windows.h>\r
+#include <stdio.h>\r
+\r
+int read_slot(const char *mailslotname)\r
+{\r
+       HANDLE h;\r
+       DWORD nr;\r
+       char data[30000];\r
+       DWORD nextsize, nummsg = 0;\r
+\r
+       if (strncmp(mailslotname, "\\\\.\\mailslot\\", 13) && strncmp(mailslotname, "\\\\*\\mailslot\\", 13)) {\r
+               printf("Must specify local mailslot name (starting with \\\\.\\mailslot\\)\n");\r
+               return 1;\r
+       }\r
+\r
+       h = CreateMailslot(mailslotname, 0, MAILSLOT_WAIT_FOREVER, NULL);\r
+\r
+       if (h == INVALID_HANDLE_VALUE) {\r
+               printf("Unable to create mailslot %s: %d\n", mailslotname, GetLastError());\r
+               return 1;\r
+       }\r
+\r
+       if (!ReadFile(h, data, sizeof(data)-1, &nr, NULL)) {\r
+               printf("Error reading: %d\n", GetLastError());\r
+               return 1;\r
+       }\r
+\r
+       data[nr] = '\0';\r
+\r
+       printf("%s\n", data);\r
+\r
+       CloseHandle(h);\r
+}\r
+\r
+int write_slot(const char *mailslotname)\r
+{\r
+       HANDLE h;\r
+       DWORD nw;\r
+       char data[30000];\r
+       h = CreateFile(mailslotname, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,  NULL);\r
+\r
+       if (h == INVALID_HANDLE_VALUE) {\r
+               printf("Unable to open file: %d\n", GetLastError());\r
+               return 1;\r
+       }\r
+\r
+       gets(data);\r
+\r
+       if (!WriteFile(h, data, strlen(data), &nw, NULL)) {\r
+               printf("Error writing file: %d\n", GetLastError());\r
+               return 1;\r
+       }\r
+\r
+       CloseHandle(h); \r
+}\r
+\r
+int main(int argc, char **argv)\r
+{\r
+       if (argc < 3 || \r
+                       (strcmp(argv[1], "read") && strcmp(argv[1], "write"))) {\r
+               printf("Usage: %s read|write mailslot\n", argv[0]);\r
+               return 1;\r
+       }\r
+\r
+       if (!strcmp(argv[1], "read")) {\r
+               return read_slot(argv[2]);\r
+       }\r
+\r
+       if (!strcmp(argv[1], "write")) {\r
+               return write_slot(argv[2]);\r
+       }\r
+\r
+       return 0;\r
+}\r