svn commit: samba r6611 - in branches/SAMBA_4_0/testprogs/win32: . testmailslot

jelmer at samba.org jelmer at samba.org
Wed May 4 10:44:51 GMT 2005


Author: jelmer
Date: 2005-05-04 10:44:50 +0000 (Wed, 04 May 2005)
New Revision: 6611

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=6611

Log:
Add mailslot test program

Added:
   branches/SAMBA_4_0/testprogs/win32/testmailslot/
   branches/SAMBA_4_0/testprogs/win32/testmailslot/Makefile
   branches/SAMBA_4_0/testprogs/win32/testmailslot/testmailslot.c


Changeset:
Added: branches/SAMBA_4_0/testprogs/win32/testmailslot/Makefile
===================================================================
--- branches/SAMBA_4_0/testprogs/win32/testmailslot/Makefile	2005-05-04 06:24:53 UTC (rev 6610)
+++ branches/SAMBA_4_0/testprogs/win32/testmailslot/Makefile	2005-05-04 10:44:50 UTC (rev 6611)
@@ -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)

Added: branches/SAMBA_4_0/testprogs/win32/testmailslot/testmailslot.c
===================================================================
--- branches/SAMBA_4_0/testprogs/win32/testmailslot/testmailslot.c	2005-05-04 06:24:53 UTC (rev 6610)
+++ branches/SAMBA_4_0/testprogs/win32/testmailslot/testmailslot.c	2005-05-04 10:44:50 UTC (rev 6611)
@@ -0,0 +1,80 @@
+/*
+ * Very simple test application for mailslots
+ * (C) 2005 Jelmer Vernooij <jelmer at 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;
+}



More information about the samba-cvs mailing list