summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Selector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/Ice/Selector.cpp')
-rw-r--r--cpp/src/Ice/Selector.cpp89
1 files changed, 88 insertions, 1 deletions
diff --git a/cpp/src/Ice/Selector.cpp b/cpp/src/Ice/Selector.cpp
index 340dffdfa1a..aadf85a1114 100644
--- a/cpp/src/Ice/Selector.cpp
+++ b/cpp/src/Ice/Selector.cpp
@@ -12,11 +12,97 @@
#include <Ice/Instance.h>
#include <Ice/LoggerUtil.h>
#include <Ice/LocalException.h>
+#include <IceUtil/Time.h>
using namespace std;
using namespace IceInternal;
-#if defined(ICE_USE_IOCP)
+#ifdef ICE_OS_WINRT
+using namespace Windows::Foundation;
+using namespace Windows::Storage::Streams;
+using namespace Windows::Networking;
+using namespace Windows::Networking::Sockets;
+
+Selector::Selector(const InstancePtr& instance) : _instance(instance)
+{
+}
+
+void
+Selector::destroy()
+{
+}
+
+void
+Selector::initialize(IceInternal::EventHandler* handler)
+{
+ handler->__incRef();
+ handler->getNativeInfo()->setCompletedHandler(
+ ref new SocketOperationCompletedHandler([=](int operation)
+ {
+ completed(handler, static_cast<SocketOperation>(operation));
+ }));
+}
+
+void
+Selector::update(IceInternal::EventHandler* handler, SocketOperation remove, SocketOperation add)
+{
+ handler->_registered = static_cast<SocketOperation>(handler->_registered & ~remove);
+ handler->_registered = static_cast<SocketOperation>(handler->_registered | add);
+ if(add & SocketOperationRead && !(handler->_pending & SocketOperationRead))
+ {
+ handler->_pending = static_cast<SocketOperation>(handler->_pending | SocketOperationRead);
+ completed(handler, SocketOperationRead); // Start an asynchrnous read
+ }
+ else if(add & SocketOperationWrite && !(handler->_pending & SocketOperationWrite))
+ {
+ handler->_pending = static_cast<SocketOperation>(handler->_pending | SocketOperationWrite);
+ completed(handler, SocketOperationWrite); // Start an asynchrnous write
+ }
+}
+
+void
+Selector::finish(IceInternal::EventHandler* handler)
+{
+ handler->_registered = SocketOperationNone;
+ handler->__decRef();
+}
+
+IceInternal::EventHandler*
+Selector::getNextHandler(SocketOperation& status, int timeout)
+{
+ Lock lock(*this);
+ while(_events.empty())
+ {
+ if(timeout > 0)
+ {
+ timedWait(IceUtil::Time::seconds(timeout));
+ if(_events.empty())
+ {
+ throw SelectorTimeoutException();
+ }
+ }
+ else
+ {
+ wait();
+ }
+ }
+ assert(!_events.empty());
+ IceInternal::EventHandler* handler = _events.front().handler;
+ status = _events.front().status;
+ _events.pop_front();
+ return handler;
+}
+
+void
+Selector::completed(IceInternal::EventHandler* handler, SocketOperation op)
+{
+ Lock lock(*this);
+ _events.push_back(SelectEvent(handler, op));
+ notify();
+}
+
+#elif defined(ICE_USE_IOCP)
+
Selector::Selector(const InstancePtr& instance) : _instance(instance)
{
}
@@ -482,6 +568,7 @@ Selector::~Selector()
void
Selector::destroy()
{
+ assert(_events.empty());
}
void