static void writeAvailableImpl(connection_t connection) { connectionContext_t* pCContext = connectionGetContext(connection); if (pCContext->status != status_waiting_write) { LOG(ERR, "Invalid state... "); } int err = completeWrite(pCContext); if (err < 0) { externalServer_t* pServer = pCContext->pExternalServer; listRemove(pServer->activeConnections, pCContext); connectionContextDelete(pCContext, 1); }else { if (err == 0) { //write compelete pCContext->status = status_active; if (dataStreamGetSize(pCContext->readStream) > 0) { readAvailableImpl(connection); }else { pCContext->status = status_waiting_read; connectionWaitForRead(pCContext->connection, getGlobalEventBase()); } }else { pCContext->status = status_waiting_write; connectionWaitForWrite(pCContext->connection, getGlobalEventBase()); } } }
void McServerSession::writeError( size_t bytesWritten, const apache::thrift::transport::TTransportException& ex) noexcept { DestructorGuard dg(this); completeWrite(); }
void McServerSession::writeSuccess() noexcept { DestructorGuard dg(this); completeWrite(); /* No-op if not paused */ resume(PAUSE_WRITE); }
void TestDocumentFileWriteJob::startWriteToFile() { TestDocumentFileSynchronizer* testSynchronizer = qobject_cast<TestDocumentFileSynchronizer*>( synchronizer() ); TestDocument* document = qobject_cast<TestDocument*>( synchronizer()->document() ); TestDocumentFileWriteThread* writeThread = new TestDocumentFileWriteThread( this, testSynchronizer->header(), document, file() ); writeThread->start(); while( !writeThread->wait(100) ) QApplication::processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 100 ); const bool success = writeThread->success(); delete writeThread; completeWrite( success ); }
void ByteArrayRawFileWriteJob::startWriteToFile() { ByteArrayDocument *document = qobject_cast<ByteArrayDocument*>( synchronizer()->document() ); ByteArrayRawFileWriteThread* writeThread = new ByteArrayRawFileWriteThread( this, document, file() ); writeThread->start(); while( !writeThread->wait(100) ) QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 100 ); const bool success = writeThread->success(); delete writeThread; // if( success ) // ExternalBookmarkStorage().writeBookmarks( document, synchronizer()->url() ); completeWrite( success ); }
static int connectionSubmitRequests(externalServer_t* pServer, connectionContext_t* pCContext) { //we have a free connection int count = MAX_MULTI_GET_REQUESTS; while (count-- > 0) { request_t* pRequest = listRemoveFirst(pServer->unassignedRequests); if (!pRequest) { break; } listAddLast(pCContext->currentRequests, pRequest); } if (listGetSize(pCContext->currentRequests) > 0) { listAddLast(pServer->activeConnections, pCContext); int bytesWritten = connectionMakeGetRequest(pCContext); if (bytesWritten > 0) { int err = completeWrite(pCContext); if (err == 0) { pCContext->status = status_waiting_read; connectionWaitForRead(pCContext->connection, getGlobalEventBase()); }else { if (err == 1) { pCContext->status = status_waiting_write; connectionWaitForWrite(pCContext->connection, getGlobalEventBase()); }else { // error writing to server/ connection closed ? listRemove(pServer->activeConnections, pCContext); connectionContextDelete(pCContext, 1); } } } }else { //pooled connections also wait for read, incase they are close by the server pCContext->status = status_pooled; listAddLast(pServer->freeConnections, pCContext); connectionWaitForRead(pCContext->connection, getGlobalEventBase()); } return 0; }