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