X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fpipe.cpp;h=831076f0086b2ffd756ec9e86a3b1b1364e9b1cc;hp=0f206981f11c6d1e205d127d281655965559187e;hb=609c9a508cfdc7b42c46c4f21d17639204165a00;hpb=b4806214e905752617691f851717033fd3f266c2 diff --git a/source/io/pipe.cpp b/source/io/pipe.cpp index 0f20698..831076f 100644 --- a/source/io/pipe.cpp +++ b/source/io/pipe.cpp @@ -1,11 +1,3 @@ -#ifndef WIN32 -#include -#include -#include -#endif -#include -#include -#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)