1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/* Author: Jan Sucan */
#include "mailslot.h"
HANDLE
mailslot_create(const char * const name)
{
return CreateMailslot(name, 0, MAILSLOT_WAIT_FOREVER, NULL);
}
unsigned
mailslot_read(HANDLE slot, char * const buf, unsigned buf_size)
{
unsigned bytes_read;
ReadFile(slot, buf, buf_size, &bytes_read, NULL);
return bytes_read;
}
HANDLE
mailslot_connect(const char * const name)
{
return CreateFile(name, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
}
int
mailslot_write(HANDLE slot, char * const buf, unsigned buf_size)
{
unsigned bytes_written;
if (WriteFile(slot, buf, buf_size, &bytes_written, NULL) == 0) {
return -1;
}
return (bytes_written != buf_size) ? -1 : 0;
}
void
mailslot_close(HANDLE slot)
{
CloseHandle(slot);
}
|