2017-11-22 16:49:37 +11:00
|
|
|
#include "handle.hpp"
|
2016-04-19 16:08:25 +10:00
|
|
|
|
2018-08-13 14:51:33 +10:00
|
|
|
#include "except.hpp"
|
2016-04-19 16:08:25 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
using cruft::win32::handle;
|
2016-04-19 16:08:25 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2016-04-27 17:01:45 +10:00
|
|
|
handle::handle ():
|
|
|
|
m_native (INVALID_HANDLE_VALUE)
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-04-19 16:08:25 +10:00
|
|
|
handle::handle (HANDLE &&h):
|
|
|
|
m_native (h)
|
|
|
|
{ ; }
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-03-27 19:07:51 +11:00
|
|
|
handle::handle (posix::fd &&rhs):
|
|
|
|
m_native (reinterpret_cast<HANDLE> (_get_osfhandle (rhs.release ())))
|
2016-04-19 16:08:25 +10:00
|
|
|
{
|
2019-03-27 19:07:51 +11:00
|
|
|
win32::error::try_value (m_native);
|
2016-04-19 16:08:25 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-22 21:34:02 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
2019-03-27 19:07:51 +11:00
|
|
|
handle::handle (cruft::win32::handle &&rhs) noexcept
|
|
|
|
: handle ()
|
2018-08-22 21:34:02 +10:00
|
|
|
{
|
2019-03-27 19:07:51 +11:00
|
|
|
std::swap (m_native, rhs.m_native);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
handle& handle::operator= (handle &&rhs) noexcept
|
|
|
|
{
|
|
|
|
std::swap (m_native, rhs.m_native);
|
|
|
|
return *this;
|
2018-08-22 21:34:02 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-19 16:08:25 +10:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
handle::~handle ()
|
|
|
|
{
|
2016-04-27 17:01:45 +10:00
|
|
|
if (m_native != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle (m_native);
|
2016-04-19 16:08:25 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
handle::operator HANDLE& (void) &
|
|
|
|
{
|
|
|
|
return native ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
HANDLE&
|
|
|
|
handle::native (void) &
|
|
|
|
{
|
|
|
|
return m_native;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
const HANDLE&
|
|
|
|
handle::native (void) const &
|
|
|
|
{
|
|
|
|
return m_native;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-27 17:01:45 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void
|
|
|
|
handle::reset (HANDLE rhs)
|
|
|
|
{
|
|
|
|
if (m_native != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle (m_native);
|
|
|
|
m_native = rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-19 16:08:25 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
handle
|
|
|
|
handle::current_process (void)
|
|
|
|
{
|
2016-08-25 12:03:48 +10:00
|
|
|
return handle (GetCurrentProcess ());
|
2016-04-19 16:08:25 +10:00
|
|
|
}
|