diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-05-04 10:44:50 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:16:30 -0500 |
commit | c531b7f66c0ffefda9417767a3fbb0e183bf3339 (patch) | |
tree | f252ed9e5e417ca336e63ac1d6a1defe42070b0e /testprogs/win32 | |
parent | 8bcfc14d645ecce7869ec5ea032b2fa2e5e65dfb (diff) | |
download | samba-c531b7f66c0ffefda9417767a3fbb0e183bf3339.tar.gz samba-c531b7f66c0ffefda9417767a3fbb0e183bf3339.tar.bz2 samba-c531b7f66c0ffefda9417767a3fbb0e183bf3339.zip |
r6611: Add mailslot test program
(This used to be commit fae95f740dde0d5c7268367a35d6f042e9f5f724)
Diffstat (limited to 'testprogs/win32')
-rw-r--r-- | testprogs/win32/testmailslot/Makefile | 10 | ||||
-rw-r--r-- | testprogs/win32/testmailslot/testmailslot.c | 80 |
2 files changed, 90 insertions, 0 deletions
diff --git a/testprogs/win32/testmailslot/Makefile b/testprogs/win32/testmailslot/Makefile new file mode 100644 index 0000000000..e307654fcb --- /dev/null +++ b/testprogs/win32/testmailslot/Makefile @@ -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 index 0000000000..b953636fd3 --- /dev/null +++ b/testprogs/win32/testmailslot/testmailslot.c @@ -0,0 +1,80 @@ +/*
+ * Very simple test application for mailslots
+ * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
+ * Published to the public domain
+ */
+
+#include <windows.h>
+#include <stdio.h>
+
+int read_slot(const char *mailslotname)
+{
+ HANDLE h;
+ DWORD nr;
+ char data[30000];
+ DWORD nextsize, nummsg = 0;
+
+ if (strncmp(mailslotname, "\\\\.\\mailslot\\", 13) && strncmp(mailslotname, "\\\\*\\mailslot\\", 13)) {
+ printf("Must specify local mailslot name (starting with \\\\.\\mailslot\\)\n");
+ return 1;
+ }
+
+ h = CreateMailslot(mailslotname, 0, MAILSLOT_WAIT_FOREVER, NULL);
+
+ if (h == INVALID_HANDLE_VALUE) {
+ printf("Unable to create mailslot %s: %d\n", mailslotname, GetLastError());
+ return 1;
+ }
+
+ if (!ReadFile(h, data, sizeof(data)-1, &nr, NULL)) {
+ printf("Error reading: %d\n", GetLastError());
+ return 1;
+ }
+
+ data[nr] = '\0';
+
+ printf("%s\n", data);
+
+ CloseHandle(h);
+}
+
+int write_slot(const char *mailslotname)
+{
+ HANDLE h;
+ DWORD nw;
+ char data[30000];
+ h = CreateFile(mailslotname, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+ if (h == INVALID_HANDLE_VALUE) {
+ printf("Unable to open file: %d\n", GetLastError());
+ return 1;
+ }
+
+ gets(data);
+
+ if (!WriteFile(h, data, strlen(data), &nw, NULL)) {
+ printf("Error writing file: %d\n", GetLastError());
+ return 1;
+ }
+
+ CloseHandle(h);
+}
+
+int main(int argc, char **argv)
+{
+ if (argc < 3 ||
+ (strcmp(argv[1], "read") && strcmp(argv[1], "write"))) {
+ printf("Usage: %s read|write mailslot\n", argv[0]);
+ return 1;
+ }
+
+ if (!strcmp(argv[1], "read")) {
+ return read_slot(argv[2]);
+ }
+
+ if (!strcmp(argv[1], "write")) {
+ return write_slot(argv[2]);
+ }
+
+ return 0;
+}
|