summaryrefslogtreecommitdiffstats
path: root/testprogs/win32/testmailslot/testmailslot.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:20:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:20:00 +0000
commit8daa83a594a2e98f39d764422bfbdbc62c9efd44 (patch)
tree4099e8021376c7d8c05bdf8503093d80e9c7bad0 /testprogs/win32/testmailslot/testmailslot.c
parentInitial commit. (diff)
downloadsamba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.tar.xz
samba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.zip
Adding upstream version 2:4.20.0+dfsg.upstream/2%4.20.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testprogs/win32/testmailslot/testmailslot.c')
-rw-r--r--testprogs/win32/testmailslot/testmailslot.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/testprogs/win32/testmailslot/testmailslot.c b/testprogs/win32/testmailslot/testmailslot.c
new file mode 100644
index 0000000..b953636
--- /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;
+}