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