5 #include <msp/core/systemerror.h>
6 #include <msp/strings/format.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();
52 void Pipe::set_block(bool b)
54 mode = (mode&~M_NONBLOCK);
56 mode = (mode|M_NONBLOCK);
59 int flags = fcntl(*handle[0], F_GETFD);
60 fcntl(*handle[0], F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
61 flags = fcntl(*handle[1], F_GETFD);
62 fcntl(*handle[1], F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
66 unsigned Pipe::do_write(const char *buf, unsigned size)
71 return sys_write(handle[1], buf, size);
74 unsigned Pipe::do_read(char *buf, unsigned size)
79 unsigned ret = reader.read(buf, size);