5 #include <msp/core/systemerror.h>
6 #include <msp/strings/formatter.h>
7 #include "handle_private.h"
16 reader(handle[0], 1024)
19 string name = format("\\\\.\\pipe\\%u.%p", GetCurrentProcessId(), this);
20 *handle[0] = CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0);
22 throw system_error("CreateNamedPipe");
24 *handle[1] = CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
27 unsigned err = GetLastError();
28 CloseHandle(*handle[0]);
29 throw system_error(format("CreateFile(%s)", name), err);
34 throw system_error("pipe");
36 *handle[0] = pipe_fd[0];
37 *handle[1] = pipe_fd[1];
47 signal_flush_required.emit();
53 void Pipe::set_block(bool b)
55 mode = (mode&~M_NONBLOCK);
57 mode = (mode|M_NONBLOCK);
60 int flags = fcntl(*handle[0], F_GETFD);
61 fcntl(*handle[0], F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
62 flags = fcntl(*handle[1], F_GETFD);
63 fcntl(*handle[1], F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
67 unsigned Pipe::do_write(const char *buf, unsigned size)
72 return sys_write(handle[1], buf, size);
75 unsigned Pipe::do_read(char *buf, unsigned size)
80 unsigned ret = reader.read(buf, size);