2 * Very simple test application for mailslots
\r
3 * (C) 2005 Jelmer Vernooij <jelmer@samba.org>
\r
4 * Published to the public domain
\r
10 int read_slot(const char *mailslotname)
\r
15 DWORD nextsize, nummsg = 0;
\r
17 if (strncmp(mailslotname, "\\\\.\\mailslot\\", 13) && strncmp(mailslotname, "\\\\*\\mailslot\\", 13)) {
\r
18 printf("Must specify local mailslot name (starting with \\\\.\\mailslot\\)\n");
\r
22 h = CreateMailslot(mailslotname, 0, MAILSLOT_WAIT_FOREVER, NULL);
\r
24 if (h == INVALID_HANDLE_VALUE) {
\r
25 printf("Unable to create mailslot %s: %d\n", mailslotname, GetLastError());
\r
29 if (!ReadFile(h, data, sizeof(data)-1, &nr, NULL)) {
\r
30 printf("Error reading: %d\n", GetLastError());
\r
36 printf("%s\n", data);
\r
41 int write_slot(const char *mailslotname)
\r
46 h = CreateFile(mailslotname, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
\r
48 if (h == INVALID_HANDLE_VALUE) {
\r
49 printf("Unable to open file: %d\n", GetLastError());
\r
55 if (!WriteFile(h, data, strlen(data), &nw, NULL)) {
\r
56 printf("Error writing file: %d\n", GetLastError());
\r
63 int main(int argc, char **argv)
\r
66 (strcmp(argv[1], "read") && strcmp(argv[1], "write"))) {
\r
67 printf("Usage: %s read|write mailslot\n", argv[0]);
\r
71 if (!strcmp(argv[1], "read")) {
\r
72 return read_slot(argv[2]);
\r
75 if (!strcmp(argv[1], "write")) {
\r
76 return write_slot(argv[2]);
\r