X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fio%2Fwindows%2Fhandle.cpp;h=e72282a4f98b0eaec2d8e5df50d3011850639e8f;hb=HEAD;hp=5b1d93368f3386adeab823b1c67c121a1cbd3264;hpb=609c9a508cfdc7b42c46c4f21d17639204165a00;p=libs%2Fcore.git diff --git a/source/io/windows/handle.cpp b/source/io/windows/handle.cpp index 5b1d933..e72282a 100644 --- a/source/io/windows/handle.cpp +++ b/source/io/windows/handle.cpp @@ -1,33 +1,41 @@ +#define NOMINMAX +#include #include #include "handle.h" #include "handle_private.h" +using namespace std; + namespace Msp { namespace IO { -Handle::operator const void *() const +void sys_set_blocking(Handle &, bool) { - return priv->handle!=INVALID_HANDLE_VALUE ? this : 0; } - -void sys_set_blocking(Handle &, bool) +void sys_set_inherit(Handle &, bool) { } -unsigned sys_read(Handle &handle, char *buf, unsigned size) +size_t sys_read(Handle &handle, char *buf, size_t size) { + if(size>numeric_limits::max()) + throw invalid_argument("IO::sys_read"); + DWORD ret; - if(ReadFile(*handle, buf, size, &ret, 0)==0) + if(ReadFile(*handle, buf, size, &ret, nullptr)==0) throw system_error("ReadFile"); return ret; } -unsigned sys_write(Handle &handle, const char *buf, unsigned size) +size_t sys_write(Handle &handle, const char *buf, size_t size) { + if(size>numeric_limits::max()) + throw invalid_argument("IO::sys_write"); + DWORD ret; - if(WriteFile(*handle, buf, size, &ret, 0)==0) + if(WriteFile(*handle, buf, size, &ret, nullptr)==0) throw system_error("WriteFile"); return ret; @@ -35,7 +43,11 @@ unsigned sys_write(Handle &handle, const char *buf, unsigned size) void sys_close(Handle &handle) { - CloseHandle(*handle); + if(handle) + { + CloseHandle(*handle); + *handle = INVALID_HANDLE_VALUE; + } } } // namespace IO