bool ArrayBuffer::transfer(ArrayBufferContents& result) { ASSERT(!isShared()); RefPtr<ArrayBuffer> keepAlive(this); if (!m_contents.data()) { result.neuter(); return false; } bool allViewsAreNeuterable = true; for (ArrayBufferView* i = m_firstView; i; i = i->m_nextView) { if (!i->isNeuterable()) allViewsAreNeuterable = false; } if (allViewsAreNeuterable) { m_contents.transfer(result); } else { m_contents.copyTo(result); if (!result.data()) return false; } while (m_firstView) { ArrayBufferView* current = m_firstView; removeView(current); if (allViewsAreNeuterable || current->isNeuterable()) current->neuter(); } m_isNeutered = true; return true; }
bool UIEulaAgreement::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CLICK) { if (ev.target->GetID() == TBIDC("quit")) { SendEvent(E_EXITREQUESTED); return true; } else if (ev.target->GetID() == TBIDC("ok")) { Editor* editor = GetSubsystem<Editor>(); if (!eulaCheck_->GetValue()) { editor->PostModalInfo("License Agreement", "Please agree to licensing terms and conditions to continue"); return true; } SharedPtr<UIEulaAgreement> keepAlive(this); GetSubsystem<UIModalOps>()->Hide(); LicenseSystem* licenseSystem = GetSubsystem<LicenseSystem>(); licenseSystem->LicenseAgreementConfirmed(); return true; } } return false; }
bool ArrayBuffer::transfer(ArrayBufferContents& result, Vector<RefPtr<ArrayBufferView> >& neuteredViews) { RefPtr<ArrayBuffer> keepAlive(this); if (!m_contents.m_data) { result.m_data = 0; return false; } bool allViewsAreNeuterable = true; for (ArrayBufferView* i = m_firstView; i; i = i->m_nextView) { if (!i->isNeuterable()) allViewsAreNeuterable = false; } if (allViewsAreNeuterable) m_contents.transfer(result); else { m_contents.copyTo(result); if (!result.m_data) return false; } while (m_firstView) { ArrayBufferView* current = m_firstView; removeView(current); if (allViewsAreNeuterable || current->isNeuterable()) current->neuter(); neuteredViews.append(current); } return true; }
TcpServer::TcpServer(io_service &service, ip::tcp::endpoint ep) : m_service(service) , m_acceptor(service, ep) { socket_base::keep_alive keepAlive(true); m_acceptor.set_option(keepAlive); }
status_t Camera3IOStreamBase::returnAnyBufferLocked( const camera3_stream_buffer &buffer, nsecs_t timestamp, bool output) { status_t res; // returnBuffer may be called from a raw pointer, not a sp<>, and we'll be // decrementing the internal refcount next. In case this is the last ref, we // might get destructed on the decStrong(), so keep an sp around until the // end of the call - otherwise have to sprinkle the decStrong on all exit // points. sp<Camera3IOStreamBase> keepAlive(this); decStrong(this); if ((res = returnBufferPreconditionCheckLocked()) != OK) { return res; } sp<Fence> releaseFence; res = returnBufferCheckedLocked(buffer, timestamp, output, &releaseFence); // Res may be an error, but we still want to decrement our owned count // to enable clean shutdown. So we'll just return the error but otherwise // carry on if (releaseFence != 0) { mCombinedFence = Fence::merge(mName, mCombinedFence, releaseFence); } if (output) { mHandoutOutputBufferCount--; } mHandoutTotalBufferCount--; if (mHandoutTotalBufferCount == 0 && mState != STATE_IN_CONFIG && mState != STATE_IN_RECONFIG && mState != STATE_PREPARING) { /** * Avoid a spurious IDLE->ACTIVE->IDLE transition when using buffers * before/after register_stream_buffers during initial configuration * or re-configuration, or during prepare pre-allocation */ ALOGV("%s: Stream %d: All buffers returned; now idle", __FUNCTION__, mId); sp<StatusTracker> statusTracker = mStatusTracker.promote(); if (statusTracker != 0) { statusTracker->markComponentIdle(mStatusId, mCombinedFence); } } mBufferReturnedSignal.signal(); if (output) { mLastTimestamp = timestamp; } return res; }
void HttpReqImpl::closeOutput() { flush(); finishChunk(); outputClosed = true; if (!keepAlive()) { inout->flush(); inout->getHandle()->closeOutput(); } }
// This is the guts of the default methods implementation. This is called just // after the classfile has been parsed if some ancestor has default methods. // // First if finds any name/signature slots that need any implementation (either // because they are miranda or a superclass's implementation is an overpass // itself). For each slot, iterate over the hierarchy, to see if they contain a // signature that matches the slot we are looking at. // // For each slot filled, we generate an overpass method that either calls the // unique default method candidate using invokespecial, or throws an exception // (in the case of no default method candidates, or more than one valid // candidate). These methods are then added to the class's method list. // The JVM does not create bridges nor handle generic signatures here. void DefaultMethods::generate_default_methods( InstanceKlass* klass, GrowableArray<Method*>* mirandas, TRAPS) { // This resource mark is the bound for all memory allocation that takes // place during default method processing. After this goes out of scope, // all (Resource) objects' memory will be reclaimed. Be careful if adding an // embedded resource mark under here as that memory can't be used outside // whatever scope it's in. ResourceMark rm(THREAD); // Keep entire hierarchy alive for the duration of the computation KeepAliveRegistrar keepAlive(THREAD); KeepAliveVisitor loadKeepAlive(&keepAlive); loadKeepAlive.run(klass); #ifndef PRODUCT if (TraceDefaultMethods) { ResourceMark rm; // be careful with these! tty->print_cr("%s %s requires default method processing", klass->is_interface() ? "Interface" : "Class", klass->name()->as_klass_external_name()); PrintHierarchy printer; printer.run(klass); } #endif // ndef PRODUCT GrowableArray<EmptyVtableSlot*>* empty_slots = find_empty_vtable_slots(klass, mirandas, CHECK); for (int i = 0; i < empty_slots->length(); ++i) { EmptyVtableSlot* slot = empty_slots->at(i); #ifndef PRODUCT if (TraceDefaultMethods) { streamIndentor si(tty, 2); tty->indent().print("Looking for default methods for slot "); slot->print_on(tty); tty->cr(); } #endif // ndef PRODUCT generate_erased_defaults(klass, empty_slots, slot, CHECK); } #ifndef PRODUCT if (TraceDefaultMethods) { tty->print_cr("Creating defaults and overpasses..."); } #endif // ndef PRODUCT create_defaults_and_exceptions(empty_slots, klass, CHECK); #ifndef PRODUCT if (TraceDefaultMethods) { tty->print_cr("Default method processing complete"); } #endif // ndef PRODUCT }
void CameraTrigger::start() { // enable immediate if configured that way if (_mode == 2) { control(true); } // Prevent camera from sleeping, if triggering is enabled if (_mode > 0 && _mode < 4) { turnOnOff(); keepAlive(true); } else { keepAlive(false); } // start to monitor at high rate for trigger enable command work_queue(LPWORK, &_work, (worker_t)&CameraTrigger::cycle_trampoline, this, USEC2TICK(1)); }
ScriptCustomElementDefinition* ScriptCustomElementDefinition::create( ScriptState* scriptState, CustomElementRegistry* registry, const CustomElementDescriptor& descriptor, const v8::Local<v8::Object>& constructor, const v8::Local<v8::Object>& prototype, const v8::Local<v8::Function>& connectedCallback, const v8::Local<v8::Function>& disconnectedCallback, const v8::Local<v8::Function>& adoptedCallback, const v8::Local<v8::Function>& attributeChangedCallback, const HashSet<AtomicString>& observedAttributes) { ScriptCustomElementDefinition* definition = new ScriptCustomElementDefinition( scriptState, descriptor, constructor, prototype, connectedCallback, disconnectedCallback, adoptedCallback, attributeChangedCallback, observedAttributes); // Add a constructor -> name mapping to the registry. v8::Local<v8::Value> nameValue = v8String(scriptState->isolate(), descriptor.name()); v8::Local<v8::Map> map = ensureCustomElementRegistryMap(scriptState, registry); map->Set(scriptState->context(), constructor, nameValue).ToLocalChecked(); definition->m_constructor.setPhantom(); // We add the prototype and callbacks here to keep them alive. We use the // name as the key because it is unique per-registry. v8::Local<v8::Array> array = v8::Array::New(scriptState->isolate(), 5); keepAlive(array, 0, prototype, definition->m_prototype, scriptState); keepAlive(array, 1, connectedCallback, definition->m_connectedCallback, scriptState); keepAlive(array, 2, disconnectedCallback, definition->m_disconnectedCallback, scriptState); keepAlive(array, 3, adoptedCallback, definition->m_adoptedCallback, scriptState); keepAlive(array, 4, attributeChangedCallback, definition->m_attributeChangedCallback, scriptState); map->Set(scriptState->context(), nameValue, array).ToLocalChecked(); return definition; }
bool ArrayBuffer::shareContentsWith(ArrayBufferContents& result) { ASSERT(isShared()); RefPtr<ArrayBuffer> keepAlive(this); if (!m_contents.data()) { result.neuter(); return false; } m_contents.shareWith(result); return true; }
ITCPServerConnHandler::Command HttpReqImpl::processHandlerResponse(natural res) { //stDetach causes waiting for user wakeup. if (res == IHttpHandler::stSleep) { return ITCPServerConnHandler::cmdWaitUserWakeup; } //depend on whether headers has been sent if (bHeaderSent) { //in case of 100 response, keep connection on-line if (res == 100) { if (!isInputAvailable()) { evType = evEndOfStream; res = curHandler->onData(*this); if (res == 100) res =500; return processHandlerResponse(res); } return ITCPServerConnHandler::cmdWaitRead; } else if (res == IHttpHandler::stWaitForWrite) { return ITCPServerConnHandler::cmdWaitWrite; } else { finish(); //keep conection depend on keep-alive return keepAlive()?ITCPServerConnHandler::cmdWaitRead:ITCPServerConnHandler::cmdRemove; } } else { //in case of 100 response if (res == 100) { if (bNeedContinue) { send100continue(); } if (!isInputAvailable()) { res = curHandler->onData(*this); if (res == 100) res =500; return processHandlerResponse(res); } //keep connection alive return ITCPServerConnHandler::cmdWaitRead; } else if (res == IHttpHandler::stWaitForWrite) { sendHeaders(); return ITCPServerConnHandler::cmdWaitWrite; } //otherwise response with status page return errorPageKA(res); } }
DouyuTcpSocket::DouyuTcpSocket(QObject *parent) :QObject(parent) { this->danmu_rid = "335166"; request_state = ""; timer = new QTimer(this); connect(&tcpDanmuSoc,SIGNAL(connected()),this,SLOT(loginAuth())); connect(&tcpDanmuSoc,SIGNAL(readyRead()),this,SLOT(readDanmuMessage())); connect(&tcpDanmuSoc,SIGNAL(error(QAbstractSocket::SocketError)), this,SLOT(displayError(QAbstractSocket::SocketError))); connect(&tcpDanmuSoc,SIGNAL(stateChanged(QAbstractSocket::SocketState)), this,SLOT(stateChanged(QAbstractSocket::SocketState))); connect(timer,SIGNAL(timeout()),this,SLOT(keepAlive())); }
void MediaSet::put (std::shared_ptr<MediaObjectImpl> mediaObject) { std::shared_ptr<AutoReleaseData> data; std::map<KmsMediaObjectId, std::shared_ptr<std::set<KmsMediaObjectId>> >::iterator it; std::shared_ptr<std::set<KmsMediaObjectId>> children; mutex.lock(); auto findIt = mediaObjectsMap.find (mediaObject->id); if (findIt != mediaObjectsMap.end() && findIt->second != NULL) { // The object is already in the mediaset mutex.unlock(); return; } if (!mediaObject->getExcludeFromGC () ) { data = std::shared_ptr<AutoReleaseData> (new AutoReleaseData() ); data->mediaSet = this; data->objectId = mediaObject->id; data->forceRemoving = isForceRemoving (mediaObject); } if (mediaObject->parent != NULL) { it = childrenMap.find (mediaObject->parent->id); if (it != childrenMap.end() ) { children = it->second; } else { children = std::shared_ptr<std::set<KmsMediaObjectId>> (new std::set<KmsMediaObjectId>() ); childrenMap[mediaObject->parent->id] = children; } children->insert (mediaObject->id); } mediaObjectsMap[mediaObject->id] = mediaObject; if (!mediaObject->getExcludeFromGC () ) { mediaObjectsAlive[mediaObject->id] = data; keepAlive (*mediaObject); } mutex.unlock(); }
void MongoWorker::handle(InitRequest *event) { try { qDebug() << "InitRequest received"; _scriptEngine = new ScriptEngine(_connection); _scriptEngine->init(event->isLoadMongoRcJs()); _scriptEngine->use(_connection->defaultDatabase()); _scriptEngine->setBatchSize(event->batchSize()); _keepAliveTimer = new QTimer(this); connect(_keepAliveTimer, SIGNAL(timeout()), this, SLOT(keepAlive())); _keepAliveTimer->start(60 * 1000); // every minute } catch (const std::exception &ex) { qDebug() << "InitRequest handler throw exception: " << ex.what(); reply(event->sender(), new InitResponse(this, EventError("Unable to initialize MongoWorker"))); } }
bool ArrayBuffer::transfer(ArrayBufferContents& result, Vector<RefPtr<ArrayBufferView> >& neuteredViews) { RefPtr<ArrayBuffer> keepAlive(this); if (!m_contents.m_data) { result.m_data = 0; return false; } m_contents.transfer(result); while (m_firstView) { ArrayBufferView* current = m_firstView; removeView(current); current->neuter(); neuteredViews.append(current); } return true; }
/* This is called from CApplication::ProcessSlow() and is used to tell if nfs have been idle for too long */ void CNFSConnection::CheckIfIdle() { /* We check if there are open connections. This is done without a lock to not halt the mainthread. It should be thread safe as worst case scenario is that m_OpenConnections could read 0 and then changed to 1 if this happens it will enter the if wich will lead to another check, wich is locked. */ if (m_OpenConnections == 0 && m_pNfsContext != NULL) { /* I've set the the maxiumum IDLE time to be 1 min and 30 sec. */ PLATFORM::CLockObject lock(*this); if (m_OpenConnections == 0 /* check again - when locked */) { if (m_IdleTimeout > 0) { m_IdleTimeout--; } else { XBMC->Log(ADDON::LOG_NOTICE, "NFS is idle. Closing the remaining connections."); Deinit(); } } } if( m_pNfsContext != NULL ) { PLATFORM::CLockObject lock(m_keepAliveLock); //handle keep alive on opened files for( tFileKeepAliveMap::iterator it = m_KeepAliveTimeouts.begin();it!=m_KeepAliveTimeouts.end();it++) { if(it->second.refreshCounter > 0) { it->second.refreshCounter--; } else { keepAlive(it->second.exportPath, it->first); //reset timeout resetKeepAlive(it->second.exportPath, it->first); } } } }
NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) override { MOZ_ASSERT(NS_IsMainThread()); MOZ_DIAGNOSTIC_ASSERT(strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC) == 0); if (!mStream) { return NS_OK; } nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(mGlobal); if (!SameCOMIdentity(aSubject, window)) { return NS_OK; } // mStream->Close() will call JSStreamConsumer::OnInputStreamReady which may // then destory itself, dropping the last reference to 'this'. RefPtr<WindowStreamOwner> keepAlive(this); mStream->Close(); mStream = nullptr; mGlobal = nullptr; return NS_OK; }
void ClientProxy1_3::handleKeepAlive(const Event&, void*) { keepAlive(); }
/** Check if result is plausible. If it is, an ok is send and the command is stored in queue. If not, a resend and ok is send. */ void GCode::checkAndPushCommand() { if(hasM()) { if(M == 110) // Reset line number { lastLineNumber = actLineNumber; Com::printFLN(Com::tOk); waitingForResend = -1; return; } if(M == 112) // Emergency kill - freeze printer { Commands::emergencyStop(); } #ifdef DEBUG_COM_ERRORS if(M == 666) // force an communication error { lastLineNumber++; return; } else if(M == 668) { lastLineNumber = 0; // simulate a reset so lines are out of resend buffer } #endif // DEBUG_COM_ERRORS } if(hasN()) { if((((lastLineNumber + 1) & 0xffff) != (actLineNumber & 0xffff))) { if(static_cast<uint16_t>(lastLineNumber - actLineNumber) < 40) { // we have seen that line already. So we assume it is a repeated resend and we ignore it commandsReceivingWritePosition = 0; Com::printFLN(Com::tSkip,actLineNumber); Com::printFLN(Com::tOk); } else if(waitingForResend < 0) // after a resend, we have to skip the garbage in buffers, no message for this { if(Printer::debugErrors()) { Com::printF(Com::tExpectedLine, lastLineNumber + 1); Com::printFLN(Com::tGot, actLineNumber); } requestResend(); // Line missing, force resend } else { --waitingForResend; commandsReceivingWritePosition = 0; Com::printFLN(Com::tSkip, actLineNumber); Com::printFLN(Com::tOk); } return; } lastLineNumber = actLineNumber; } /* This test is not compatible with all hosts. Replaced by forbidding backward switch of protocols. else if(lastLineNumber && !(hasM() && M == 117)) { // once line number always line number! if(Printer::debugErrors()) { Com::printErrorFLN(PSTR("Missing linenumber")); } requestResend(); return; }*/ if(GCode::hasFatalError() && !(hasM() && M==999)) { GCode::reportFatalError(); } else { pushCommand(); } #ifdef DEBUG_COM_ERRORS if(hasM() && M == 667) return; // omit ok #endif #if ACK_WITH_LINENUMBER Com::printFLN(Com::tOkSpace, actLineNumber); #else Com::printFLN(Com::tOk); #endif wasLastCommandReceivedAsBinary = sendAsBinary; keepAlive(NotBusy); waitingForResend = -1; // everything is ok. }
void ChatServer::sendKeepAlive() { emit keepAlive(); m_keepAliveCheckTimer->start(); }
/** \brief Read from serial console or sdcard. This function is the main function to read the commands from serial console or from sdcard. It must be called frequently to empty the incoming buffer. */ void GCode::readFromSerial() { if(bufferLength >= GCODE_BUFFER_SIZE || (waitUntilAllCommandsAreParsed && bufferLength)) { keepAlive(Processing); return; // all buffers full } waitUntilAllCommandsAreParsed = false; millis_t time = HAL::timeInMilliseconds(); if(!HAL::serialByteAvailable()) { if((waitingForResend >= 0 || commandsReceivingWritePosition > 0) && time - timeOfLastDataPacket > 200) { // Com::printF(PSTR("WFR:"),waitingForResend);Com::printF(PSTR(" CRWP:"),commandsReceivingWritePosition);commandReceiving[commandsReceivingWritePosition] = 0;Com::printFLN(PSTR(" GOT:"),(char*)commandReceiving); requestResend(); // Something is wrong, a started line was not continued in the last second timeOfLastDataPacket = time; } #ifdef WAITING_IDENTIFIER else if(bufferLength == 0 && time - timeOfLastDataPacket > 1000) // Don't do it if buffer is not empty. It may be a slow executing command. { Com::printFLN(Com::tWait); // Unblock communication in case the last ok was not received correct. timeOfLastDataPacket = time; } #endif } while(HAL::serialByteAvailable() && commandsReceivingWritePosition < MAX_CMD_SIZE) // consume data until no data or buffer full { timeOfLastDataPacket = time; //HAL::timeInMilliseconds(); commandReceiving[commandsReceivingWritePosition++] = HAL::serialReadByte(); // first lets detect, if we got an old type ascii command if(commandsReceivingWritePosition == 1) { if(waitingForResend >= 0 && wasLastCommandReceivedAsBinary) { if(!commandReceiving[0]) waitingForResend--; // Skip 30 zeros to get in sync else waitingForResend = 30; commandsReceivingWritePosition = 0; continue; } if(!commandReceiving[0]) // Ignore zeros { commandsReceivingWritePosition = 0; continue; } sendAsBinary = (commandReceiving[0] & 128) != 0; } if(sendAsBinary) { if(commandsReceivingWritePosition < 2 ) continue; if(commandsReceivingWritePosition == 5 || commandsReceivingWritePosition == 4) binaryCommandSize = computeBinarySize((char*)commandReceiving); if(commandsReceivingWritePosition == binaryCommandSize) { GCode *act = &commandsBuffered[bufferWriteIndex]; if(act->parseBinary(commandReceiving, true)) // Success act->checkAndPushCommand(); else requestResend(); commandsReceivingWritePosition = 0; return; } } else // Ascii command { char ch = commandReceiving[commandsReceivingWritePosition - 1]; if(ch == 0 || ch == '\n' || ch == '\r' || (!commentDetected && ch == ':')) // complete line read { commandReceiving[commandsReceivingWritePosition - 1] = 0; //Com::printF(PSTR("Parse ascii:"));Com::print((char*)commandReceiving);Com::println(); commentDetected = false; if(commandsReceivingWritePosition == 1) // empty line ignore { commandsReceivingWritePosition = 0; continue; } GCode *act = &commandsBuffered[bufferWriteIndex]; if(act->parseAscii((char *)commandReceiving, true)) // Success act->checkAndPushCommand(); else requestResend(); commandsReceivingWritePosition = 0; return; } else { if(ch == ';') commentDetected = true; // ignore new data until line end if(commentDetected) commandsReceivingWritePosition--; } } if(commandsReceivingWritePosition == MAX_CMD_SIZE) { requestResend(); return; } } #if SDSUPPORT if(sd.sdmode == 0 || sd.sdmode >= 100 || commandsReceivingWritePosition != 0) // not reading or incoming serial command return; while( sd.filesize > sd.sdpos && commandsReceivingWritePosition < MAX_CMD_SIZE) // consume data until no data or buffer full { timeOfLastDataPacket = HAL::timeInMilliseconds(); int n = sd.file.read(); if(n == -1) { Com::printFLN(Com::tSDReadError); UI_ERROR("SD Read Error"); // Second try in case of recoverable errors sd.file.seekSet(sd.sdpos); n = sd.file.read(); if(n == -1) { Com::printErrorFLN(PSTR("SD error did not recover!")); sd.sdmode = 0; break; } UI_ERROR("SD error fixed"); } sd.sdpos++; // = file.curPosition(); commandReceiving[commandsReceivingWritePosition++] = (uint8_t)n; // first lets detect, if we got an old type ascii command if(commandsReceivingWritePosition == 1) { sendAsBinary = (commandReceiving[0] & 128) != 0; } if(sendAsBinary) { if(commandsReceivingWritePosition < 2 ) continue; if(commandsReceivingWritePosition == 4 || commandsReceivingWritePosition == 5) binaryCommandSize = computeBinarySize((char*)commandReceiving); if(commandsReceivingWritePosition == binaryCommandSize) { GCode *act = &commandsBuffered[bufferWriteIndex]; if(act->parseBinary(commandReceiving, false)) // Success, silently ignore illegal commands pushCommand(); commandsReceivingWritePosition = 0; if(sd.sdmode == 2) sd.sdmode = 0; return; } } else { char ch = commandReceiving[commandsReceivingWritePosition-1]; bool returnChar = ch == '\n' || ch == '\r'; if(returnChar || sd.filesize == sd.sdpos || (!commentDetected && ch == ':') || commandsReceivingWritePosition >= (MAX_CMD_SIZE - 1) ) // complete line read { if(returnChar || ch == ':') commandReceiving[commandsReceivingWritePosition - 1] = 0; else commandReceiving[commandsReceivingWritePosition] = 0; commentDetected = false; if(commandsReceivingWritePosition == 1) // empty line ignore { commandsReceivingWritePosition = 0; continue; } GCode *act = &commandsBuffered[bufferWriteIndex]; if(act->parseAscii((char *)commandReceiving, false)) // Success pushCommand(); commandsReceivingWritePosition = 0; if(sd.sdmode == 2) sd.sdmode = 0; return; } else { if(ch == ';') commentDetected = true; // ignore new data until line end if(commentDetected) commandsReceivingWritePosition--; } } } sd.sdmode = 0; Com::printFLN(Com::tDonePrinting); commandsReceivingWritePosition = 0; commentDetected = false; Printer::setMenuMode(MENU_MODE_SD_PRINTING, false); #endif }
int App::Logic() { auto configResult = SZ::Config::Me()->LoadConfig("./config.json"); if (!EnsureCorrectness(*configResult, "App config error", "")) { delete configResult; return -1; } delete configResult; RegisterCommonLuaFunctions(); std::thread keepAlive(std::bind(&App::KeepAliveThread, this)); keepAlive.detach(); int connectionFailures = 0; while (true) // currently never leaves this loop { if (!mConn) { mConn = new SSLSocketClient(); } else { mConn->Close(); // to restart client from scratch } if (!EnsureCorrectness(mConn->Init(), "Connection error", "")) { Sleep(3); ++connectionFailures; if (connectionFailures >= FAILURE_COUNT_TO_RECONNECT_SCRIPT) { connectionFailures = 0; SZ::LuaModule module; if (!EnsureCorrectness(module.Init(LuaModule::MODULE_MODEM_CONN), "Reconnecting script init error", "", nullptr)) { continue; } if (!EnsureCorrectness(module.Call("", ""), "Reconnecting script Lua call error", "", nullptr)) { continue; } } continue; } connectionFailures = 0; SZ::JSONClientMessage initialMessage; initialMessage.Init(LuaModule::MODULE_INIT, "", BoardId(), "OK", ""); if (!EnsureCorrectness(mConn->Send(initialMessage.Create()), "Initial sending error", "", mConn)) { Sleep(3); continue; } mConn->Listen([&](const std::string &command) { SZ::JSONServerMessage message; if (!EnsureCorrectness(message.Decode(command), "JSON decode error", "", mConn)) { return; } HandleServerMessage(message); mKeepAliveCounter = 0; }); delete mConn; mConn = nullptr; } keepAlive.join(); SZ::LuaStateControl::Destroy(); return 0; }
void CTestMessageComposer::SetHeaderL(TInt aNumberofHeaders) { switch (aNumberofHeaders) { case 1: { // Open strings used in this test //1.Accept header---- Accept: text/html; q=0.8, text/vnd.wap.wml; q=0.2; extended=value, text/*); RStringF textHtml = iStringPool.StringF(HTTP::ETextHtml,RHTTPSession::GetTable()); RStringF textWml = iStringPool.StringF(HTTP::ETextVndWapWml,RHTTPSession::GetTable()); RStringF textAny = iStringPool.StringF(HTTP::ETextAny,RHTTPSession::GetTable()); RStringF extended = iStringPool.OpenFStringL(_L8("extended")); CleanupClosePushL(extended); RStringF extendVal = iStringPool.OpenFStringL(_L8("value")); CleanupClosePushL(extendVal); iHTTPHeaders = iTransaction.Request().GetHeaderCollection(); RStringF accept = iStringPool.StringF(HTTP::EAccept,RHTTPSession::GetTable()); THTTPHdrVal accVal(textHtml); THTTPHdrVal q1(THTTPHdrVal::TQConv(0.8)); iHTTPHeaders.SetFieldL(accept, accVal, iStringPool.StringF(HTTP::EQ,RHTTPSession::GetTable()), q1); accVal.SetStrF(textWml); q1.SetInt(THTTPHdrVal::TQConv(0.2)); iHTTPHeaders.SetFieldL(accept, accVal, iStringPool.StringF(HTTP::EQ,RHTTPSession::GetTable()), q1); q1.SetStrF(extendVal); iHTTPHeaders.SetFieldL(accept, accVal, extended, q1); accVal.SetStrF(textAny); iHTTPHeaders.SetFieldL(accept, accVal); CleanupStack::PopAndDestroy(2, &extended); //2.Accept-Charset header-- Accept-Charset: iso-8859-5, unicode-1-1; q=0.8 RStringF iso8859_5 = iStringPool.OpenFStringL(_L8("iso-8859-5")); CleanupClosePushL(iso8859_5); RStringF unicode1_1 = iStringPool.OpenFStringL(_L8("unicode-1-1")); CleanupClosePushL(unicode1_1); RStringF accChSet= iStringPool.StringF(HTTP::EAcceptCharset,RHTTPSession::GetTable()); THTTPHdrVal accChSetVal(iso8859_5); iHTTPHeaders.SetFieldL(accChSet, accChSetVal); // accChSetVal.SetStrF(unicode1_1); THTTPHdrVal q2(THTTPHdrVal::TQConv(0.8)); iHTTPHeaders.SetFieldL(accChSet, accChSetVal, iStringPool.StringF(HTTP::EQ,RHTTPSession::GetTable()), q2); CleanupStack::PopAndDestroy(2, &iso8859_5); //3.User-Agent headers-- User-Agent: CERN-LineMode/2.15 libwww/2.17b3 // Open strings used in this test RStringF ua1Str = iStringPool.OpenFStringL(_L8("CERN-LineMode/2.15")); CleanupClosePushL(ua1Str); RStringF ua2Str = iStringPool.OpenFStringL(_L8("libwww/2.17b3")); CleanupClosePushL(ua2Str); // RStringF uaStr = iStringPool.StringF(HTTP::EUserAgent,RHTTPSession::GetTable()); THTTPHdrVal uaVal(ua1Str); iHTTPHeaders.SetFieldL(uaStr, uaVal); // sets part 1 uaVal.SetStrF(ua2Str); iHTTPHeaders.SetFieldL(uaStr, uaVal); // sets part 2 CleanupStack::PopAndDestroy(2,&ua1Str); //4.Connection Header -- Connection: close, keep-alive RStringF otherToken = iStringPool.StringF(HTTP::EKeepAlive,RHTTPSession::GetTable()); RStringF connStr = iStringPool.StringF(HTTP::EConnection,RHTTPSession::GetTable()); THTTPHdrVal connVal(iStringPool.StringF(HTTP::EClose,RHTTPSession::GetTable())); iHTTPHeaders.SetFieldL(connStr, connVal); // sets part 1 THTTPHdrVal keepAlive(otherToken); iHTTPHeaders.SetFieldL(connStr, keepAlive); // sets part 2 //5.content type header-- Content-Type: text/vnd.wap.wml; charset=utf-8; transcode=yes RStringF textWml1 = iStringPool.StringF(HTTP::ETextVndWapWml,RHTTPSession::GetTable()); RStringF utf8 = iStringPool.OpenFStringL(_L8("utf-8")); CleanupClosePushL(utf8); RStringF extended1 = iStringPool.OpenFStringL(_L8("transcode")); CleanupClosePushL(extended1); RStringF extendVal1 = iStringPool.OpenFStringL(_L8("yes")); CleanupClosePushL(extendVal1); // RStringF contType = iStringPool.StringF(HTTP::EContentType,RHTTPSession::GetTable()); THTTPHdrVal ctVal(textWml1); THTTPHdrVal chSet(utf8); iHTTPHeaders.SetFieldL(contType, ctVal, iStringPool.StringF(HTTP::ECharset,RHTTPSession::GetTable()), chSet); chSet.SetStrF(extendVal1); iHTTPHeaders.SetFieldL(contType, ctVal, extended1, chSet); CleanupStack::PopAndDestroy(3,&utf8); //6.host type header-- Host: nokia.com RStringF host1Str = iStringPool.OpenFStringL(_L8("www.nokia.com")); CleanupClosePushL(host1Str); RStringF host = iStringPool.StringF(HTTP::EHost,RHTTPSession::GetTable()); THTTPHdrVal hostVal(host1Str); iHTTPHeaders.SetFieldL(host, hostVal); CleanupStack::PopAndDestroy(&host1Str); //7.upgrade type header-- Upgrade: HTTP/2.0, SHTTP/1.3 RStringF http = iStringPool.OpenFStringL(_L8("HTTP/2.0")); CleanupClosePushL(http); RStringF shttp = iStringPool.OpenFStringL(_L8("SHTTP/1.3")); CleanupClosePushL(shttp); RStringF upgradeStr = iStringPool.StringF(HTTP::EUpgrade, RHTTPSession::GetTable()); THTTPHdrVal val(http); THTTPHdrVal val2(shttp); iHTTPHeaders.SetFieldL(upgradeStr, val); iHTTPHeaders.SetFieldL(upgradeStr, val2); CleanupStack::PopAndDestroy(2); //8.Cache control -- Cache-Control: public, no-cache=\"wibble,wobble\" _LIT8(KPublic, "public"); _LIT8(KNoCache, "no-cache=\"wibble,wobble\""); RStringF publicStr = iStringPool.OpenFStringL(KPublic); CleanupClosePushL(publicStr); RStringF noCacheStr = iStringPool.OpenFStringL(KNoCache); CleanupClosePushL(noCacheStr); RStringF cc = iStringPool.StringF(HTTP::ECacheControl,RHTTPSession::GetTable()); iHTTPHeaders.SetFieldL(cc, THTTPHdrVal(publicStr)); iHTTPHeaders.SetFieldL(cc, THTTPHdrVal(noCacheStr)); CleanupStack::PopAndDestroy(2,&publicStr); //9.Authorization-- Authorization: Basic c3ltYmlhbjpmMXN5bmNtbA== RString basicCred = iStringPool.OpenStringL(_L8("c3ltYmlhbjpmMXN5bmNtbA==")); CleanupClosePushL(basicCred); RStringF authStr = iStringPool.StringF(HTTP::EAuthorization,RHTTPSession::GetTable()); THTTPHdrVal authVal(iStringPool.StringF(HTTP::EBasic,RHTTPSession::GetTable())); iHTTPHeaders.SetFieldL(authStr, authVal); // sets part 1 THTTPHdrVal credVal(basicCred); iHTTPHeaders.SetFieldL(authStr, credVal); // sets part 2 CleanupStack::PopAndDestroy(&basicCred); break; } case 2: { //1. Connection: Keep-Alive\r\n RStringF keep = iStringPool.StringF(HTTP::EKeepAlive,RHTTPSession::GetTable()); iHTTPHeaders = iTransaction.Request().GetHeaderCollection(); RStringF Connection= iStringPool.StringF(HTTP::EConnection,RHTTPSession::GetTable()); THTTPHdrVal keepalive(keep); iHTTPHeaders.SetFieldL(Connection,keepalive); //2.Host: 192.168.100.100\r\n _LIT8(KHostIp, "192.168.100.100"); RStringF host2Str = iStringPool.OpenFStringL(KHostIp); CleanupClosePushL(host2Str); RStringF host2= iStringPool.StringF(HTTP::EHost,RHTTPSession::GetTable()); THTTPHdrVal hostip(host2Str); iHTTPHeaders.SetFieldL(host2,hostip); CleanupStack::PopAndDestroy(&host2Str); //3.Accept: */*\r\n _LIT8(KAccept2, "*/*"); RStringF acceptall = iStringPool.OpenFStringL(KAccept2); CleanupClosePushL(acceptall); RStringF accept2= iStringPool.StringF(HTTP::EAccept,RHTTPSession::GetTable()); THTTPHdrVal acceptvalue(acceptall); iHTTPHeaders.SetFieldL(accept2,acceptvalue); CleanupStack::PopAndDestroy(&acceptall); //4.Accept-Charset: iso-8859-1,utf-8;q=0.7,*;q=0.7\r\n RStringF iso8859 = iStringPool.OpenFStringL(_L8("iso-8859-1")); CleanupClosePushL(iso8859); RStringF utf8_1 = iStringPool.OpenFStringL(_L8("utf-8")); CleanupClosePushL(utf8_1); RStringF all = iStringPool.OpenFStringL(_L8("*")); CleanupClosePushL(all); RStringF accChSet1= iStringPool.StringF(HTTP::EAcceptCharset,RHTTPSession::GetTable()); THTTPHdrVal accChSetVal1(iso8859); iHTTPHeaders.SetFieldL(accChSet1, accChSetVal1); accChSetVal1.SetStrF(utf8_1); THTTPHdrVal q3(THTTPHdrVal::TQConv(0.7)); iHTTPHeaders.SetFieldL(accChSet1, accChSetVal1, iStringPool.StringF(HTTP::EQ,RHTTPSession::GetTable()), q3); accChSetVal1.SetStrF(all); iHTTPHeaders.SetFieldL(accChSet1, accChSetVal1, iStringPool.StringF(HTTP::EQ,RHTTPSession::GetTable()), q3); CleanupStack::PopAndDestroy(3,&iso8859); //5.Accept-Encoding: gzip, deflate, x-gzip, identity; q=0.9\r\n RStringF gzip = iStringPool.OpenFStringL(_L8("gzip")); CleanupClosePushL(gzip); RStringF deflate = iStringPool.OpenFStringL(_L8("deflate")); CleanupClosePushL(deflate); RStringF xgzip = iStringPool.OpenFStringL(_L8("x-gzip")); CleanupClosePushL(xgzip); RStringF identity = iStringPool.OpenFStringL(_L8("identity")); CleanupClosePushL(identity); RStringF acceptencoding1= iStringPool.StringF(HTTP::EAcceptEncoding,RHTTPSession::GetTable()); THTTPHdrVal aevalue(gzip); iHTTPHeaders.SetFieldL(acceptencoding1, aevalue); aevalue.SetStrF(deflate); iHTTPHeaders.SetFieldL(acceptencoding1, aevalue); aevalue.SetStrF(xgzip); iHTTPHeaders.SetFieldL(acceptencoding1, aevalue); aevalue.SetStrF(identity); THTTPHdrVal q4(THTTPHdrVal::TQConv(0.9)); iHTTPHeaders.SetFieldL(acceptencoding1, aevalue, iStringPool.StringF(HTTP::EQ,RHTTPSession::GetTable()), q4); CleanupStack::PopAndDestroy(4,&gzip); //6.Accept-Language: en;q=1.0,bg;q=0.5,nl;q=0.5,fr;q=0.5\r\n RStringF en = iStringPool.OpenFStringL(_L8("en")); CleanupClosePushL(en); RStringF bg = iStringPool.OpenFStringL(_L8("bg")); CleanupClosePushL(bg); RStringF nl = iStringPool.OpenFStringL(_L8("nl")); CleanupClosePushL(nl); RStringF fr = iStringPool.OpenFStringL(_L8("fr")); CleanupClosePushL(fr); RStringF acceptlanguage1= iStringPool.StringF(HTTP::EAcceptLanguage,RHTTPSession::GetTable()); THTTPHdrVal alvalue(en); THTTPHdrVal q5(THTTPHdrVal::TQConv(1.0)); iHTTPHeaders.SetFieldL(acceptlanguage1, alvalue, iStringPool.StringF(HTTP::EQ,RHTTPSession::GetTable()), q5); THTTPHdrVal q6(THTTPHdrVal::TQConv(0.5)); alvalue.SetStrF(bg); iHTTPHeaders.SetFieldL(acceptlanguage1, alvalue, iStringPool.StringF(HTTP::EQ,RHTTPSession::GetTable()), q6); alvalue.SetStrF(nl); iHTTPHeaders.SetFieldL(acceptlanguage1, alvalue, iStringPool.StringF(HTTP::EQ,RHTTPSession::GetTable()), q6); alvalue.SetStrF(fr); iHTTPHeaders.SetFieldL(acceptlanguage1, alvalue, iStringPool.StringF(HTTP::EQ,RHTTPSession::GetTable()), q6); CleanupStack::PopAndDestroy(4,&en); //7.Referer: http://192.168.100.100/il/index.html\r\n RStringF referer = iStringPool.OpenFStringL(_L8("http://192.168.100.100/il/index.html")); CleanupClosePushL(referer); RStringF refer= iStringPool.StringF(HTTP::EReferer,RHTTPSession::GetTable()); THTTPHdrVal referval(referer); iHTTPHeaders.SetFieldL(refer,referval); CleanupStack::PopAndDestroy(&referer); //8.User-Agent: Mozilla/5.0 AppleWebKit/525 RStringF ua1Str1 = iStringPool.OpenFStringL(_L8("Mozilla/5.0")); CleanupClosePushL(ua1Str1); RStringF ua2Str2 = iStringPool.OpenFStringL(_L8("AppleWebKit/525")); CleanupClosePushL(ua2Str2); RStringF uaString = iStringPool.StringF(HTTP::EUserAgent,RHTTPSession::GetTable()); THTTPHdrVal uaVal1(ua1Str1); iHTTPHeaders.SetFieldL(uaString, uaVal1); // sets part 1 uaVal1.SetStrF(ua2Str2); iHTTPHeaders.SetFieldL(uaString, uaVal1); // sets part 2 CleanupStack::PopAndDestroy(2,&ua1Str1); break; } default: break; } }
bool UINewProject::OnEvent(const TBWidgetEvent &ev) { Editor* editor = GetSubsystem<Editor>(); UIModalOps* ops = GetSubsystem<UIModalOps>(); if (ev.type == EVENT_TYPE_CLICK) { if (ev.target->GetID() == TBIDC("cancel")) { ops->Hide(); return true; } int projectType = -1; if (ev.target->GetID() == TBIDC("project_empty")) { projectType = 0; } else if (ev.target->GetID() == TBIDC("project_2d")) { projectType = 1; } else if (ev.target->GetID() == TBIDC("project_3d")) { // BEGIN LICENSE MANAGEMENT LicenseSystem* licenseSystem = GetSubsystem<LicenseSystem>(); if (licenseSystem->IsStandardLicense()) { SharedPtr<UINewProject> keepAlive(this); UIModalOps* ops = GetSubsystem<UIModalOps>(); ops->Hide(); ops->ShowInfoModule3D(); return true; } // END LICENSE MANAGEMENT projectType = 2; } if (projectType != -1) { FileSystem* fileSystem = GetSubsystem<FileSystem>(); #ifdef ATOMIC_PLATFORM_OSX String templateSourceDir = fileSystem->GetAppBundleResourceFolder(); #else String templateSourceDir = fileSystem->GetProgramDir(); #endif if (projectType == 0) templateSourceDir += "/ProjectTemplates/EmptyProject"; else if (projectType == 1) templateSourceDir += "/ProjectTemplates/Project2D"; else templateSourceDir += "/ProjectTemplates/Project3D"; SharedPtr<UINewProject> keepAlive(this); UIModalOps* ops = GetSubsystem<UIModalOps>(); ops->Hide(); ops->ShowCreateProject(templateSourceDir); return true; } } return false; }