]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/pipe.cpp
Move most platform-specific code into overlay directories
[libs/core.git] / source / io / pipe.cpp
index 0f206981f11c6d1e205d127d281655965559187e..831076f0086b2ffd756ec9e86a3b1b1364e9b1cc 100644 (file)
@@ -1,11 +1,3 @@
-#ifndef WIN32
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#endif
-#include <msp/core/systemerror.h>
-#include <msp/strings/format.h>
-#include "handle_private.h"
 #include "pipe.h"
 
 using namespace std;
@@ -18,27 +10,7 @@ Pipe::Pipe():
 {
        mode = M_RDWR;
 
-#ifdef WIN32
-       string name = format("\\\\.\\pipe\\%u.%p", GetCurrentProcessId(), this);
-       *read_handle = CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0);
-       if(!read_handle)
-               throw system_error("CreateNamedPipe");
-
-       *write_handle = CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
-       if(!write_handle)
-       {
-               unsigned err = GetLastError();
-               CloseHandle(*read_handle);
-               throw system_error(format("CreateFile(%s)", name), err);
-       }
-#else
-       int pipe_fd[2];
-       if(pipe(pipe_fd)==-1)
-               throw system_error("pipe");
-
-       *read_handle = pipe_fd[0];
-       *write_handle = pipe_fd[1];
-#endif
+       platform_init();
 
        set_events(P_INPUT);
 }
@@ -58,12 +30,8 @@ void Pipe::set_block(bool b)
        if(b)
                mode = (mode|M_NONBLOCK);
 
-#ifndef WIN32
-       int flags = fcntl(*read_handle, F_GETFD);
-       fcntl(*read_handle, F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
-       flags = fcntl(*write_handle, F_GETFD);
-       fcntl(*write_handle, F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
-#endif
+       sys_set_blocking(read_handle, b);
+       sys_set_blocking(write_handle, b);
 }
 
 unsigned Pipe::do_write(const char *buf, unsigned size)