X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fpipe.cpp;h=afa0c259bdc3655195ccca692439774f8f967d8b;hp=b3735aa63b6d43a7724aaa13d1109ce96a78b0d2;hb=8f2711fba7a2817840038630d9cf9a2060ecbe8e;hpb=c7afef88380ebebc8c2b04e48664d73281ec8848 diff --git a/source/io/pipe.cpp b/source/io/pipe.cpp index b3735aa..afa0c25 100644 --- a/source/io/pipe.cpp +++ b/source/io/pipe.cpp @@ -2,6 +2,7 @@ #include #include #endif +#include #include #include "pipe.h" @@ -16,14 +17,14 @@ Pipe::Pipe() string name = format("\\\\.\\pipe\\%u.%p", GetCurrentProcessId(), this); handle[0] = CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0); if(handle[0]==INVALID_HANDLE_VALUE) - throw SystemError("Unable to create pipe", GetLastError()); + throw system_error("CreateNamedPipe"); handle[1] = CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if(handle[1]==INVALID_HANDLE_VALUE) { unsigned err = GetLastError(); CloseHandle(handle[0]); - throw SystemError("Unable to create pipe", err); + throw system_error(format("CreateFile(%s)", name), err); } overlapped = 0; @@ -34,7 +35,7 @@ Pipe::Pipe() buf_next = buffer; #else if(pipe(handle)==-1) - throw SystemError("Unable to create pipe", errno); + throw system_error("pipe"); #endif set_events(P_INPUT); @@ -82,7 +83,7 @@ unsigned Pipe::do_write(const char *buf, unsigned size) #ifdef WIN32 DWORD ret; if(!WriteFile(handle[1], buf, size, &ret, 0)) - throw SystemError("Writing to pipe failed", GetLastError()); + throw system_error("WriteFile"); #else int ret = ::write(handle[1], buf, size); if(ret==-1) @@ -90,7 +91,7 @@ unsigned Pipe::do_write(const char *buf, unsigned size) if(errno==EAGAIN) return 0; else - throw SystemError("Writing to pipe failed", errno); + throw system_error("write"); } #endif @@ -110,7 +111,7 @@ unsigned Pipe::do_read(char *buf, unsigned size) { DWORD ret; if(!GetOverlappedResult(handle[0], overlapped, &ret, !buf_avail)) - throw SystemError("Reading from pipe failed", GetLastError()); + throw system_error("GetOverlappedResult"); else { buf_avail += ret; @@ -133,7 +134,7 @@ unsigned Pipe::do_read(char *buf, unsigned size) if(errno==EAGAIN) return 0; else - throw SystemError("Reading from pipe failed", errno); + throw system_error("read"); } #endif @@ -161,7 +162,7 @@ Handle Pipe::get_event_handle() { unsigned err = GetLastError(); if(err!=ERROR_IO_PENDING) - throw SystemError("Failed to start an overlapped read", err); + throw system_error("ReadFile"); } else {