aboutsummaryrefslogtreecommitdiff
path: root/testing/yup-comm/mailslot.c
diff options
context:
space:
mode:
authorJan Sucan <sucanjan@fit.cvut.cz>2019-06-04 14:34:27 +0200
committerJan Sucan <sucanjan@fit.cvut.cz>2019-06-04 14:34:27 +0200
commitdc8703206e3f0f69605c56d0e1127f7e17f3476a (patch)
tree166823a741dc420c10d54250cb53d1e3a6b74faf /testing/yup-comm/mailslot.c
Initial commit
Diffstat (limited to 'testing/yup-comm/mailslot.c')
-rw-r--r--testing/yup-comm/mailslot.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/testing/yup-comm/mailslot.c b/testing/yup-comm/mailslot.c
new file mode 100644
index 0000000..a18f21e
--- /dev/null
+++ b/testing/yup-comm/mailslot.c
@@ -0,0 +1,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);
+}