#include <errno.h>
+#include <stdexcept>
+#include <msp/core/systemerror.h>
#include <msp/strings/formatter.h>
#include <msp/time/units.h>
-#include "except.h"
#include "base.h"
#include "poll.h"
+using namespace std;
+
namespace {
using namespace Msp;
int result = 0;
if(event&~(P_INPUT|P_PRIO|P_OUTPUT))
- throw InvalidParameterValue("Invalid poll events");
+ throw invalid_argument("sys_poll_event");
#ifndef WIN32
if(event&P_INPUT)
if(ret==WAIT_OBJECT_0)
return pe;
else if(ret==WAIT_FAILED)
- throw SystemError("Poll failed", GetLastError());
+ throw system_error("WaitForSingleObject");
return P_NONE;
#else
if(errno==EINTR)
return P_NONE;
else
- throw SystemError("Poll failed", errno);
+ throw system_error("poll");
}
return poll_event_from_sys(pfd.revents);
{
#ifdef WIN32
if(objects.size()>=MAXIMUM_WAIT_OBJECTS)
- throw InvalidState("Maximum number of wait objects reached");
+ throw logic_error("Maximum number of wait objects reached");
#endif
objects.insert(SlotMap::value_type(&obj, Slot(&obj, ev)));
int Poller::poll(const Time::TimeDelta &timeout)
{
if(timeout<Time::zero)
- throw InvalidParameterValue("Invalid timeout");
+ throw invalid_argument("Poller::poll");
return do_poll(static_cast<int>(timeout/Time::msec));
}
return 1;
}
else if(ret==WAIT_FAILED)
- throw SystemError("Poll failed", GetLastError());
+ throw system_error("WaitForMultipleObjects");
return 0;
#else
if(errno==EINTR)
return 0;
else
- throw SystemError("Poll failed", errno);
+ throw system_error("poll");
}
int n = ret;
PollEvent poll(Base &obj, PollEvent pe, const Time::TimeDelta &timeout)
{
if(timeout<Time::zero)
- throw InvalidParameterValue("Invalid timeout");
+ throw invalid_argument("poll");
return do_poll(obj, pe, static_cast<int>(timeout/Time::msec));
}