+ CASocketFd_t socketArray[EVENT_ARRAY_SIZE];
+ HANDLE eventArray[EVENT_ARRAY_SIZE];
+ int arraySize = 0;
+ int eventIndex;
+
+ // socketArray and eventArray should have same number of elements
+ OC_STATIC_ASSERT(_countof(socketArray) == _countof(eventArray), "Arrays should have same number of elements");
+
+ PUSH_IP_SOCKET(u6, eventArray, socketArray, arraySize);
+ PUSH_IP_SOCKET(u6s, eventArray, socketArray, arraySize);
+ PUSH_IP_SOCKET(u4, eventArray, socketArray, arraySize);
+ PUSH_IP_SOCKET(u4s, eventArray, socketArray, arraySize);
+ PUSH_IP_SOCKET(m6, eventArray, socketArray, arraySize);
+ PUSH_IP_SOCKET(m6s, eventArray, socketArray, arraySize);
+ PUSH_IP_SOCKET(m4, eventArray, socketArray, arraySize);
+ PUSH_IP_SOCKET(m4s, eventArray, socketArray, arraySize);
+
+ if (WSA_INVALID_EVENT != caglobals.ip.shutdownEvent)
+ {
+ INSERT_SOCKET(OC_INVALID_SOCKET, socketArray, arraySize);
+ PUSH_HANDLE(caglobals.ip.shutdownEvent, eventArray, arraySize);
+ }
+
+ /** @todo Support netlink events */
+
+ // Should not have overflowed buffer
+ assert(arraySize <= (_countof(socketArray)));
+
+ // Timeout is unnecessary on Windows
+ assert(-1 == caglobals.ip.selectTimeout);
+
+ while (!caglobals.ip.terminate)
+ {
+ int ret = WSAWaitForMultipleEvents(arraySize, eventArray, FALSE, WSA_INFINITE, FALSE);
+
+ switch (ret)
+ {
+ case WSA_WAIT_FAILED:
+ OIC_LOG_V(ERROR, TAG, "WSAWaitForMultipleEvents returned WSA_WAIT_FAILED 0x%08x", WSAGetLastError());
+ break;
+ case WSA_WAIT_IO_COMPLETION:
+ OIC_LOG_V(ERROR, TAG, "WSAWaitForMultipleEvents returned WSA_WAIT_IO_COMPLETION 0x%08x", WSAGetLastError());
+ break;
+ case WSA_WAIT_TIMEOUT:
+ OIC_LOG_V(ERROR, TAG, "WSAWaitForMultipleEvents returned WSA_WAIT_TIMEOUT 0x%08x", WSAGetLastError());
+ break;
+ default:
+ eventIndex = ret - WSA_WAIT_EVENT_0;
+ if ((eventIndex >= 0) && (eventIndex < arraySize))
+ {
+ if (false == WSAResetEvent(eventArray[eventIndex]))
+ {
+ OIC_LOG_V(ERROR, TAG, "WSAResetEvent failed 0x%08x", WSAGetLastError());
+ }
+
+ // Break out if shutdownEvent is triggered.
+ if ((caglobals.ip.shutdownEvent != WSA_INVALID_EVENT) &&
+ (caglobals.ip.shutdownEvent == eventArray[eventIndex]))
+ {
+ break;
+ }
+ CAEventReturned(socketArray[eventIndex]);
+ }
+ else
+ {
+ OIC_LOG_V(ERROR, TAG, "WSAWaitForMultipleEvents failed 0x%08x", WSAGetLastError());
+ }
+ break;
+ }
+
+ }
+
+ while (arraySize > 0)
+ {
+ arraySize--;
+ if (!WSACloseEvent(eventArray[arraySize]))
+ {
+ OIC_LOG_V(ERROR, TAG, "WSACloseEvent (Index %i) failed 0x%08x", arraySize, WSAGetLastError());
+ }
+ }