void _glfwPlatformPollEvents(void) { EventNode* node = NULL; while ((node = dequeueEvent(_glfw.mir.event_queue))) { handleEvent(node->event, node->window); deleteNode(_glfw.mir.event_queue, node); } }
void DccVoiceThread::run() { #ifndef COMPILE_DISABLE_DCC_VOICE for(;;) { // m_uSleepTime = 0; // Dequeue events while(KviThreadEvent * e = dequeueEvent()) { if(e->id() == KVI_THREAD_EVENT_TERMINATE) { delete e; goto exit_dcc; } else if(e->id() == KVI_DCC_THREAD_EVENT_ACTION) { int * act = ((KviThreadDataEvent<int> *)e)->getData(); if(*act)startRecording(); else stopRecording(); delete act; delete e; } else { // Other events are senseless to us delete e; } } if(!readWriteStep())goto exit_dcc; if(!soundStep())goto exit_dcc; m_pInfoMutex->lock(); m_iInputBufferSize = m_inSignalBuffer.size(); m_iOutputBufferSize = (m_outFrameBuffer.size() / m_pOpt->pCodec->encodedFrameSize()) * m_pOpt->pCodec->decodedFrameSize(); m_pInfoMutex->unlock(); // Actually the maximum that we can sleep here is // around 500 usecs... = 0.0005 sec -> 8 bytes at 8 KHz // if(m_uSleepTime)usleep(m_uSleepTime); // Start recording if the request was not fulfilled yet if(m_bRecordingRequestPending)startRecording(); } exit_dcc: #endif //! COMPILE_DISABLE_DCC_VOICE closeSoundcard(); kvi_socket_close(m_fd); m_fd = KVI_INVALID_SOCKET; }
bool IDBOpenDBRequest::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event) { // If the connection closed between onUpgradeNeeded and the delivery of the "success" event, // an "error" event should be fired instead. if (event->type() == EventTypeNames::success && resultAsAny()->type() == IDBAny::IDBDatabaseType && resultAsAny()->idbDatabase()->isClosePending()) { dequeueEvent(event.get()); setResult(nullptr); onError(DOMError::create(AbortError, "The connection was closed.")); return false; } return IDBRequest::dispatchEvent(event); }
bool IDBRequest::dispatchEvent(PassRefPtr<Event> event) { IDB_TRACE("IDBRequest::dispatchEvent"); if (m_contextStopped || !executionContext()) return false; ASSERT(m_requestState.isValid()); ASSERT(m_readyState == PENDING); ASSERT(m_hasPendingActivity); ASSERT(m_enqueuedEvents.size()); ASSERT(event->target() == this); DOMRequestState::Scope scope(m_requestState); if (event->type() != EventTypeNames::blocked) m_readyState = DONE; dequeueEvent(event.get()); Vector<RefPtr<EventTarget> > targets; targets.append(this); if (m_transaction && !m_preventPropagation) { targets.append(m_transaction); // If there ever are events that are associated with a database but // that do not have a transaction, then this will not work and we need // this object to actually hold a reference to the database (to ensure // it stays alive). targets.append(m_transaction->db()); } // Cursor properties should not be updated until the success event is being dispatched. RefPtr<IDBCursor> cursorToNotify; if (event->type() == EventTypeNames::success) { cursorToNotify = getResultCursor(); if (cursorToNotify) cursorToNotify->setValueReady(m_cursorKey.release(), m_cursorPrimaryKey.release(), m_cursorValue.release()); } if (event->type() == EventTypeNames::upgradeneeded) { ASSERT(!m_didFireUpgradeNeededEvent); m_didFireUpgradeNeededEvent = true; } // FIXME: When we allow custom event dispatching, this will probably need to change. ASSERT_WITH_MESSAGE(event->type() == EventTypeNames::success || event->type() == EventTypeNames::error || event->type() == EventTypeNames::blocked || event->type() == EventTypeNames::upgradeneeded, "event type was %s", event->type().string().utf8().data()); const bool setTransactionActive = m_transaction && (event->type() == EventTypeNames::success || event->type() == EventTypeNames::upgradeneeded || (event->type() == EventTypeNames::error && !m_requestAborted)); if (setTransactionActive) m_transaction->setActive(true); bool dontPreventDefault = IDBEventDispatcher::dispatch(event.get(), targets); if (m_transaction) { if (m_readyState == DONE) m_transaction->unregisterRequest(this); // Possibly abort the transaction. This must occur after unregistering (so this request // doesn't receive a second error) and before deactivating (which might trigger commit). if (event->type() == EventTypeNames::error && dontPreventDefault && !m_requestAborted) { m_transaction->setError(m_error); m_transaction->abort(IGNORE_EXCEPTION); } // If this was the last request in the transaction's list, it may commit here. if (setTransactionActive) m_transaction->setActive(false); } if (cursorToNotify) cursorToNotify->postSuccessHandlerCallback(); // An upgradeneeded event will always be followed by a success or error event, so must // be kept alive. if (m_readyState == DONE && event->type() != EventTypeNames::upgradeneeded) m_hasPendingActivity = false; return dontPreventDefault; }
void DccChatThread::run() { KviDccThreadIncomingData data; data.iLen = 0; data.buffer = nullptr; for(;;) { // Dequeue events while(KviThreadEvent * e = dequeueEvent()) { if(e->id() == KVI_THREAD_EVENT_TERMINATE) { delete e; goto out_of_the_loop; } else { // Other events are senseless to us delete e; } } bool bCanRead; bool bCanWrite; if(kvi_select(m_fd, &bCanRead, &bCanWrite)) { if(bCanWrite) { if(!tryFlushOutBuffers()) goto out_of_the_loop; } if(bCanRead) { data.buffer = (char *)KviMemory::reallocate(data.buffer, (data.iLen + 512) * sizeof(char)); int readLen; #ifdef COMPILE_SSL_SUPPORT if(m_pSSL) { readLen = m_pSSL->read(data.buffer + data.iLen, 512); } else { #endif readLen = kvi_socket_recv(m_fd, data.buffer + data.iLen, 512); #ifdef COMPILE_SSL_SUPPORT } #endif if(readLen > 0) { data.iLen += readLen; data.buffer = (char *)KviMemory::reallocate(data.buffer, data.iLen * sizeof(char)); if(!handleIncomingData(&data, false)) break; // non critical... } else { #ifdef COMPILE_SSL_SUPPORT if(m_pSSL) { // ssl error....? switch(m_pSSL->getProtocolError(readLen)) { case KviSSL::ZeroReturn: readLen = 0; break; case KviSSL::WantRead: case KviSSL::WantWrite: // hmmm... break; case KviSSL::SyscallError: { int iE = m_pSSL->getLastError(true); if(iE != 0) { raiseSSLError(); postErrorEvent(KviError::SSLError); goto out_of_the_loop; } } break; case KviSSL::SSLError: { raiseSSLError(); postErrorEvent(KviError::SSLError); goto out_of_the_loop; } break; default: // Raise unknown SSL ERROR postErrorEvent(KviError::SSLError); goto out_of_the_loop; break; } } #endif if(data.iLen > 0) { data.buffer = (char *)KviMemory::reallocate(data.buffer, data.iLen * sizeof(char)); } else { KviMemory::free(data.buffer); data.buffer = nullptr; } if(!handleInvalidSocketRead(readLen)) { if(data.iLen) handleIncomingData(&data, true); // critical KVI_ASSERT(!data.iLen); break; // error } } } msleep(100); } } out_of_the_loop: if(data.iLen) KviMemory::free(data.buffer); #ifdef COMPILE_SSL_SUPPORT if(m_pSSL) { KviSSLMaster::freeSSL(m_pSSL); m_pSSL = nullptr; } #endif if(m_fd != KVI_INVALID_SOCKET) ::kvi_socket_close(m_fd); m_fd = KVI_INVALID_SOCKET; }