]> git.tdb.fi Git - libs/core.git/blob - source/io/windows/pipe.cpp
Use default member initializers and constructor delegation
[libs/core.git] / source / io / windows / pipe.cpp
1 #include <msp/core/systemerror.h>
2 #include <msp/strings/format.h>
3 #include "handle_private.h"
4 #include "pipe.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace IO {
10
11 void Pipe::platform_init()
12 {
13         string name = format("\\\\.\\pipe\\%u.%p", GetCurrentProcessId(), this);
14         *read_handle = CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0);
15         if(!read_handle)
16                 throw system_error("CreateNamedPipe");
17
18         *write_handle = CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
19         if(!write_handle)
20         {
21                 unsigned err = GetLastError();
22                 CloseHandle(*read_handle);
23                 throw system_error(format("CreateFile(%s)", name), err);
24         }
25 }
26
27 } // namespace IO
28 } // namespace Msp