void ajax::dispatchQueue(const QUrl& url) { if( url.isEmpty() ) { QMapIterator<QUrl, QVariantList> i(mRequestQueue); while( i.hasNext() ) { i.next(); QVariantMap req; req["actions"] = i.value(); dispatchRequest(i.key(), req); } mRequestQueue.clear(); mRequestQueueTimer->stop(); } else { QVariantMap m_request; m_request["actions"] = mRequestQueue.take(url); dispatchRequest(url, m_request); if( mRequestQueue.isEmpty() ) mRequestQueueTimer->stop(); } }
/** * Do some sanity checks and forward message to the proper handler */ void MsgpackIODevice::dispatch(msgpack_object& req) { // // neovim msgpack rpc calls are // [type(int), msgid(int), method(int), args(array)] // if (req.type != MSGPACK_OBJECT_ARRAY) { qDebug() << "Received Invalid msgpack: not an array"; return; } if (req.via.array.size < 3 || req.via.array.size > 4) { qDebug() << "Received Invalid msgpack: message len MUST be 3 or 4"; return; } if (req.via.array.ptr[0].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { qDebug() << "Received Invalid msgpack: msg type MUST be an integer"; return; } uint64_t type = req.via.array.ptr[0].via.u64; switch(type) { case 0: if (req.via.array.ptr[1].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { qDebug() << "Received Invalid request: msg id MUST be a positive integer"; sendError(req, tr("Msg Id must be a positive integer")); return; } if (req.via.array.ptr[2].type != MSGPACK_OBJECT_BIN && req.via.array.ptr[2].type != MSGPACK_OBJECT_STR) { qDebug() << "Received Invalid request: method MUST be a String" << req.via.array.ptr[2]; sendError(req, tr("Method id must be a positive integer")); return; } if (req.via.array.ptr[3].type != MSGPACK_OBJECT_ARRAY) { qDebug() << "Invalid request: arguments MUST be an array"; sendError(req, tr("Paremeters must be an array")); return; } dispatchRequest(req); break; case 1: if (req.via.array.ptr[1].type != MSGPACK_OBJECT_POSITIVE_INTEGER) { qDebug() << "Received Invalid response: msg id MUST be a positive integer"; return; } dispatchResponse(req); break; case 2: dispatchNotification(req); break; default: qDebug() << "Unsupported msg type" << type; } }
void CCPomelo::dispatchCallbacks(float delta){ int _taskCount = 0; pthread_mutex_lock(&task_count_mutex); _taskCount = task_count; pthread_mutex_unlock(&task_count_mutex); if (_taskCount == 0) return; dispatchNotify(); dispatchEvent(); dispatchRequest(); }
void CCPomelo::dispatchCallbacks(float delta){ dispatchNotify(); dispatchEvent(); dispatchRequest(); if (connect_status==1) { connectCallBack(); } pthread_mutex_lock(&task_count_mutex); if (task_count==0) { CCDirector::sharedDirector()->getScheduler()->pauseTarget(this); } pthread_mutex_unlock(&task_count_mutex); }
static void dmaIRQHandler(uint32_t controller) { uint32_t intTCStatusReg; uint32_t intTCClearReg; uint32_t intTCStatus; if(controller == 1) { intTCStatusReg = DMAC0 + DMACIntTCStatus; intTCClearReg = DMAC0 + DMACIntTCClear; } else { intTCStatusReg = DMAC1 + DMACIntTCStatus; intTCClearReg = DMAC1 + DMACIntTCClear; } intTCStatus = GET_REG(intTCStatusReg); int channel; for(channel = 0; channel < DMA_NUMCHANNELS; channel++) { if((intTCStatus & (1 << channel)) != 0) { dispatchRequest(&requests[controller - 1][channel], controller, channel); SET_REG(intTCClearReg, 1 << channel); } } }
//Internal run method that does all the hard work int TFTPserv::run() { // Setup timeout fd_set recvSet; fd_set sendSet; int n; //Main packet-handling loop shuttingDown = false; while (shuttingDown == false){ FD_ZERO(&recvSet); FD_SET(smellySock, &recvSet); FD_ZERO(&sendSet); //Do we need to check for sent items? Let's see for (set<map<string, unsigned int> *>::iterator it = transfers.begin(); it != transfers.end(); ++it){ if ((*(*it))["lastSent"] != 0){ FD_SET(smellySock, &recvSet); break; } } struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; n = select((int)(smellySock + 1), &recvSet, &sendSet, NULL, &tv); if (n == -1) { break; //Error } //Get request char receiveBuf[bufferSize]; struct sockaddr client; int clientLength = sizeof(client); int receiveSize = 0; if (n != 0) { receiveSize = recvfrom(smellySock, receiveBuf, bufferSize, 0, &client, &clientLength); } if (receiveSize > 0) { string data(receiveBuf, receiveSize); dispatchRequest(*((sockaddr_in *)&client), data); } //Now see if we need to transmit/retransmit another block for (set<map<string, unsigned int> *>::iterator it = transfers.begin(); it != transfers.end(); ++it) { map<string, unsigned int> & transfer = *(*it); if (transfer["type"] != OpRead) { continue; } if (transfer["lastSent"] != 0) { checkRetransmission(transfer); } else { string block = files[transfer["file"]].substr(transfer["offset"], transfer["blksize"]); if (block.size() > 0) { string packet(htonstring(OpData)); packet.append(htonstring(transfer["block"])); packet.append(block); //Send packet //first get address sockaddr_in client; memset((void*)&client, 0, sizeof(client)); client.sin_family = AF_INET; *((unsigned int *)&client.sin_addr) = transfer["fromIp"]; client.sin_port = (unsigned short)transfer["fromPort"]; //whew. now send sendto(smellySock, packet.c_str(), (int)packet.size(), 0, (sockaddr*)&client, (int)sizeof(sockaddr_in)); transfer["lastSent"] = clock() / CLOCKS_PER_SEC; } } } } closesocket(smellySock); return 0; }
void Dispatcher::ProcessFirstPacket(PhysicalConnection* pChannel, unsigned int uCommand, IncomingPacket& packet, unsigned int serviceBytes) { OutgoingPacket* pOutPacket = NULL; // LogicalConnection* pClient; int iResult = pServerImpl->getClientFactory()->onFirstRequest(packet, pChannel->GetConnectionContext(), pClient, pOutPacket); //packet and lpContext are not good. if (iResult == ClientFactory::RefuseAndClose) { pChannel->PushPacket(pOutPacket); pChannel->Close(false); return; } if (iResult == ClientFactory::RefuseRequest) { if (pOutPacket) { pChannel->PushPacket(pOutPacket); pServerImpl->getFacade()->disposeOutgoingPacket(pOutPacket); } return; } std::string clientKey = pClient->getKey(); //iResult >= CClientFactory::CreateClient if (!channelFactory.RemoveFromUnattachedList(pChannel)) { delete pClient; pChannel->decrementIoWorkersReferenceCounter(); return; } //Bind the two structures. pClient->pPhysicalConnection = pChannel; pChannel->attachToClient(pClient); //status is attached. stats.addToCumul(ServerStats::VisitorsHitsIn, 1); LogicalConnection* pRet = clientFactoryImpl.AddLogicalConnection(pClient); if (pRet != pClient) { //Copy data from existing to new instance. pServerImpl->getClientFactory()->CopyLogicalConnection(pRet, pClient); //Silent disconnect : clientFactoryImpl.SilentDisconnect(pRet); //Now add ours : clientFactoryImpl.AddLogicalConnection(pClient); //Fire Reconnect event. pServerImpl->getClientFactory()->onClientReconnected(pClient); //Add client to a streamer : broadcastStreamerManager.AddClient(pClient); pClient->DecrementUsage(); return; } //Fire connect event. pServerImpl->getClientFactory()->onClientConnected(pClient); //Add client to a streamer : broadcastStreamerManager.AddClient(pClient); //Statistics : NotifyObserversClientIN(clientKey.c_str(), pChannel->getPeerIP(), pChannel->getPeerPort()); stats.addToCumul(ServerStats::VisitorsOnline, 1); if (iResult == ClientFactory::CreateAndRouteRequest) { dispatchRequest(uCommand, pClient, packet, serviceBytes); } else { if (pOutPacket) { pChannel->PushPacket(pOutPacket); pServerImpl->getFacade()->disposeOutgoingPacket(pOutPacket); } } pClient->DecrementUsage(); }
bool RestData::dispatchCyclicRequest() { return dispatchRequest(defaultRequest); }
void Dispatcher::OnReceiveComplete(PhysicalConnection* pChannel, int dwIoSize) { int status = pChannel->ReadReceivedBytes(dwIoSize); if (status < PhysicalConnection::Connected) { pChannel->decrementIoWorkersReferenceCounter(); return; } bool isClient = !pChannel->isObserverChannel(); //Channel is either connected or attached. if (dwIoSize == 0)//Peer wants to close the connection. { pChannel->Close(false); if (status == PhysicalConnection::Attached) { if (isClient) { pServerImpl->getClientFactory()->onClientDisconnected(pChannel->getLogicalConnection()); } else { //TODO notify observer is out. } } pChannel->decrementIoWorkersReferenceCounter(); return; } if (isClient) { stats.addToCumul(ServerStats::BandwidthInbound, dwIoSize); stats.addToKeyedDuration(ServerStats::BandwidthInboundPerConnection, (unsigned int) pChannel, dwIoSize); } //The Processing Loop. int uCommandID; IncomingPacket* pPacket; int iResult; unsigned int uExtractedBytes; Protocol* pProtocol = pChannel->getProtocol(); DataBuffer& sourceBuffer = pChannel->GetReceiveBuffer(); bool bProcessDataInQueue = true; while (bProcessDataInQueue) { iResult = pProtocol->tryDeserializeIncomingPacket(sourceBuffer, pPacket, uCommandID, uExtractedBytes); if (iResult == Protocol::Success) { pChannel->GetReceiveBuffer().Pop(uExtractedBytes); if (status == PhysicalConnection::Attached) { if (isClient) dispatchRequest(uCommandID, pChannel->getLogicalConnection(), *pPacket, uExtractedBytes); else HandleMonitorRequest(pChannel, *pPacket); } else if (status == PhysicalConnection::Connected) { if (isClient) ProcessFirstPacket(pChannel, uCommandID, *pPacket, uExtractedBytes); else ProcessMonitorFirstPacket(pChannel, *pPacket); } else { //Status changed by another thread eg ::disconnect. bProcessDataInQueue = false; } pProtocol->disposeIncomingPacket(pPacket); } else if (iResult == Protocol::eDecodingFailure) { pChannel->GetReceiveBuffer().Pop(uExtractedBytes); } else break; } // if (iResult == Protocol::eIncompletePacket && pChannel->getStatus() >= PhysicalConnection::Connected) { ioQueue.RearmSocketInputEvents(pChannel->getSocket(), pChannel); pChannel->incrementIoWorkersReferenceCounter(); //pChannel->PostReceive(); } pChannel->decrementIoWorkersReferenceCounter(); }