bool RedisClient::SshTransporter::connectToHost() { ConnectionConfig config = m_connection->getConfig(); if (config.isSshPasswordUsed()) m_sshClient->setPassphrase(config.sshPassword()); QString privateKey = config.getSshPrivateKey(); if (!privateKey.isEmpty()) { m_sshClient->setKeyFiles("", privateKey); } //connect to ssh server SignalWaiter waiter(config.connectionTimeout()); waiter.addAbortSignal(this, &RedisClient::SshTransporter::errorOccurred); waiter.addSuccessSignal(m_sshClient.data(), &QxtSshClient::connected); emit logEvent("Connecting to SSH host..."); m_sshClient->connectToHost(config.sshUser(), config.sshHost(), config.sshPort()); if (!waiter.wait()) { emit errorOccurred("Cannot connect to SSH host"); return false; } emit logEvent("SSH tunnel established. Connecting to redis-server..."); return openTcpSocket(); }
bool CGUIDialogBusy::Wait(IRunnable *runnable, unsigned int displaytime /* = 100 */, bool allowCancel /* = true */) { if (!runnable) return false; CBusyWaiter waiter(runnable); return waiter.Wait(displaytime, allowCancel); }
CDataHistoryInfo CDataFeed::GetQuoteHistoryFiles(const string& symbol, bool includeLevel2, CDateTime time, const uint32 timeoutInMilliseconds) { Waiter<CFxDataHistoryResponse> waiter(timeoutInMilliseconds, cExternalSynchCall, *this); CFxDataHistoryRequest request(symbol); request.BarsNumber = 0; request.Time = time; request.PriceType = FxPriceType_None; request.ReportType = FX_REPORT_TYPE_FILE; request.GraphType = includeLevel2 ? FX_GRAPH_TYPE_LEVEL2 : FX_GRAPH_TYPE_TICKS; m_sender->VSendDataHistoryRequest(waiter.Id(), request); CFxDataHistoryResponse response = waiter.WaitForResponse(); CDataHistoryInfo result; std::swap(result.Files, response.Files); if ((response.From > time) || (response.To < time)) { result.Files.clear(); } result.FromAll = response.FromAll; result.ToAll = response.ToAll; if (!result.Files.empty()) { result.From = response.From; result.To = response.To; } std::swap(result.LastTickId, response.LastTickId); return result; }
bool wait_queue_t::wait(duration_t* timeout) { if(FIBER_IMPL) { fiber_waiter_t waiter(FIBER_IMPL, SCHEDULER_IMPL); waiters_.push_back(waiter); auto wait_res = SCHEDULER_IMPL->wait_queue(lock_, timeout); waiters_.erase(waiters_.iterator_to(waiter)); if(waiter.wakeup_next) notify_one(); return wait_res == scheduler_impl_t::READY; } else { native_waiter_t waiter; waiter.queue_lock = lock_; waiters_.push_back(waiter); bool wait_successfull = waiter.wait(timeout); waiters_.erase(waiters_.iterator_to(waiter)); if(waiter.wakeup_next) notify_one(); return wait_successfull; } }
int Socket::Read(ByteArray & buffer) { char raw[MAX_BUFFER_SIZE]; if (!open) return 0; buffer.v.clear(); // Allow interruption of block. FlexWait waiter(2,this,&terminator); Blockable * result = waiter.Wait(); // This happens if the call was shutdown on this side if (result == &terminator) { terminator.Reset(); return 0; } // If we got here, we need to read the socket // Messages greater than MAX_BUFFER_SIZE are not handled gracefully. ssize_t received = recv(GetFD(), raw, MAX_BUFFER_SIZE, 0); for (int i=0;i<received;i++) buffer.v.push_back(raw[i]); if (received <=0) open = false; return received; }
CDataHistoryInfo CDataFeed::GetBarsHistoryFiles(const string& symbol, int32 priceType, const string& period, CDateTime time, uint32 timeoutInMilliseconds) { Waiter<CFxDataHistoryResponse> waiter(timeoutInMilliseconds, cExternalSynchCall, *this); CFxDataHistoryRequest request(symbol, period); request.BarsNumber = 0; request.Time = time; request.PriceType = priceType; request.ReportType = FX_REPORT_TYPE_FILE; request.GraphType = FX_GRAPH_TYPE_BARS; m_sender->VSendDataHistoryRequest(waiter.Id(), request); CFxDataHistoryResponse response = waiter.WaitForResponse(); CDataHistoryInfo result; std::swap(result.Files, response.Files); result.FromAll = response.FromAll; result.ToAll = response.ToAll; if (!result.Files.empty()) { result.From = response.From; result.To = response.To; } result.LastTickId = response.LastTickId; return result; }
// Check that initialization / destruction works without crashing. TEST(SocketWaiter, init) { ScopedPtr<SocketWaiter> waiter(SocketWaiter::create()); unsigned events = ~0U; EXPECT_EQ(-1, waiter->nextPendingFd(&events)); EXPECT_EQ(0, events); }
TEST(SocketWaiter, update) { ScopedPtr<SocketWaiter> waiter(SocketWaiter::create()); int s1, s2; ASSERT_EQ(0, socketCreatePair(&s1, &s2)); waiter->update(s1, SocketWaiter::kEventRead); waiter->update(s2, SocketWaiter::kEventWrite); EXPECT_TRUE(waiter->hasFds()); EXPECT_EQ(SocketWaiter::kEventRead, waiter->wantedEventsFor(s1)); EXPECT_EQ(SocketWaiter::kEventWrite, waiter->wantedEventsFor(s2)); waiter->update(s1, SocketWaiter::kEventWrite); waiter->update(s2, SocketWaiter::kEventRead); EXPECT_TRUE(waiter->hasFds()); EXPECT_EQ(SocketWaiter::kEventWrite, waiter->wantedEventsFor(s1)); EXPECT_EQ(SocketWaiter::kEventRead, waiter->wantedEventsFor(s2)); waiter->update(s1, SocketWaiter::kEventRead | SocketWaiter::kEventWrite); waiter->update(s2, SocketWaiter::kEventRead | SocketWaiter::kEventWrite); EXPECT_TRUE(waiter->hasFds()); EXPECT_EQ(SocketWaiter::kEventRead | SocketWaiter::kEventWrite, waiter->wantedEventsFor(s1)); EXPECT_EQ(SocketWaiter::kEventRead | SocketWaiter::kEventWrite, waiter->wantedEventsFor(s2)); waiter->reset(); EXPECT_FALSE(waiter->hasFds()); EXPECT_EQ(0U, waiter->wantedEventsFor(s1)); EXPECT_EQ(0U, waiter->wantedEventsFor(s2)); }
bool CGUIDialogBusy::Wait(IRunnable *runnable) { if (!runnable) return false; CBusyWaiter waiter(runnable); return waiter.Wait(); }
string CDataFeed::GetTicksHistoryMetaInfoFile(const string& symbol, bool includeLevel2, const uint32 timeoutInMilliseconds) { Waiter<string> waiter(timeoutInMilliseconds, cExternalSynchCall, *this); m_sender->VSendGetTicksHistoryMetaInfoFile(waiter.Id(), symbol, includeLevel2); string result = waiter.WaitForResponse(); return result; }
s32 sceKernelWaitEventFlag(ARMv7Thread& context, s32 evfId, u32 bitPattern, u32 waitMode, vm::ptr<u32> pResultPat, vm::ptr<u32> pTimeout) { sceLibKernel.Error("sceKernelWaitEventFlag(evfId=0x%x, bitPattern=0x%x, waitMode=0x%x, pResultPat=*0x%x, pTimeout=*0x%x)", evfId, bitPattern, waitMode, pResultPat, pTimeout); const u64 start_time = pTimeout ? get_system_time() : 0; const u32 timeout = pTimeout ? pTimeout->value() : 0; const auto evf = idm::get<psv_event_flag_t>(evfId); if (!evf) { return SCE_KERNEL_ERROR_INVALID_UID; } std::unique_lock<std::mutex> lock(evf->mutex); const u32 result = evf->pattern.atomic_op(event_flag_try_poll, bitPattern, waitMode); if (event_flag_test(result, bitPattern, waitMode)) { if (pResultPat) *pResultPat = result; return SCE_OK; } // fixup register values for external use context.GPR[1] = bitPattern; context.GPR[2] = waitMode; // add waiter; attributes are ignored in current implementation sleep_queue_entry_t waiter(context, evf->sq); while (!context.unsignal()) { CHECK_EMU_STATUS; if (pTimeout) { const u64 passed = get_system_time() - start_time; if (passed >= timeout) { context.GPR[0] = SCE_KERNEL_ERROR_WAIT_TIMEOUT; context.GPR[1] = evf->pattern; break; } context.cv.wait_for(lock, std::chrono::microseconds(timeout - passed)); } else { context.cv.wait(lock); } } if (pResultPat) *pResultPat = context.GPR[1]; if (pTimeout) *pTimeout = static_cast<u32>(std::max<s64>(0, timeout - (get_system_time() - start_time))); return context.GPR[0]; }
s32 _sys_lwcond_queue_wait(PPUThread& ppu, u32 lwcond_id, u32 lwmutex_id, u64 timeout) { sys_lwcond.Log("_sys_lwcond_queue_wait(lwcond_id=0x%x, lwmutex_id=0x%x, timeout=0x%llx)", lwcond_id, lwmutex_id, timeout); const u64 start_time = get_system_time(); LV2_LOCK; const auto cond = idm::get<lv2_lwcond_t>(lwcond_id); const auto mutex = idm::get<lv2_lwmutex_t>(lwmutex_id); if (!cond || !mutex) { return CELL_ESRCH; } // finalize unlocking the mutex mutex->unlock(lv2_lock); // add waiter; protocol is ignored in current implementation sleep_queue_entry_t waiter(ppu, cond->sq); // potential mutex waiter (not added immediately) sleep_queue_entry_t mutex_waiter(ppu, cond->sq, defer_sleep); while (!ppu.unsignal()) { CHECK_EMU_STATUS; if (timeout && waiter) { const u64 passed = get_system_time() - start_time; if (passed >= timeout) { // try to reown the mutex if timed out if (mutex->signaled) { mutex->signaled--; return CELL_EDEADLK; } else { return CELL_ETIMEDOUT; } } ppu.cv.wait_for(lv2_lock, std::chrono::microseconds(timeout - passed)); } else { ppu.cv.wait(lv2_lock); } } // return cause return ppu.GPR[3] ? CELL_EBUSY : CELL_OK; }
CFxAccountInfo CDataTrade::GetAccountInfo(const uint32 timeoutInMilliseconds) { Waiter<CFxAccountInfo> waiter(timeoutInMilliseconds, cExternalSynchCall, *this); m_sender->VSendGetAccountInfo(waiter.Id()); CFxAccountInfo result = waiter.WaitForResponse(); return result; }
QScriptValue Mail::waitForEncrypted(int waitTime) { QxtSignalWaiter waiter(&mSmtp, SIGNAL(encrypted())); if(!waiter.wait(waitTime)) throwError("EncryptionError", tr("Cannot encrypt the connection")); return thisObject(); }
QScriptValue Mail::waitForConnected(int waitTime) { QxtSignalWaiter waiter(&mSmtp, SIGNAL(connected())); if(!waiter.wait(waitTime)) throwError("ConnectionError", tr("Cannot establish a connection to the server")); return thisObject(); }
QScriptValue Mail::waitForDisconnected(int waitTime) { QxtSignalWaiter waiter(&mSmtp, SIGNAL(disconnected())); if(!waiter.wait(waitTime)) throwError("WaitForDisconnectedError", tr("Wait for disconnected failed")); return thisObject(); }
QScriptValue Mail::waitForAuthenticated(int waitTime) { QxtSignalWaiter waiter(&mSmtp, SIGNAL(authenticated())); if(!waiter.wait(waitTime)) throwError("AuthenticationError", tr("Cannot authenticate to the server")); return thisObject(); }
bool CDataTrade::CloseByOrders(const string& firstOrderId, const string& secondOrderId, const size_t timeoutInMilliseconds) { Waiter<CFxClosePositionsResponse> waiter(static_cast<uint32>(timeoutInMilliseconds), cExternalSynchCall, *this); m_sender->VSendCloseByOrders(waiter.Id(), firstOrderId, secondOrderId); CFxClosePositionsResponse response = waiter.WaitForResponse(); const bool result = SUCCEEDED(response.Status); return result; }
vector<CFxSymbolInfo> CDataFeed::GetSupportedSymbols(uint32 timeoutInMilliseconds) { Waiter<vector<CFxSymbolInfo> > waiter(timeoutInMilliseconds, cExternalSynchCall, *this); m_sender->VSendGetSupportedSymbols(waiter.Id()); vector<CFxSymbolInfo> result = waiter.WaitForResponse(); return result; }
string CDataFeed::GetBarsHistoryMetaInfoFile(const string& symbol, FxPriceType priceType, const string& period, const uint32 timeoutInMilliseconds) { Waiter<string> waiter(timeoutInMilliseconds, cExternalSynchCall, *this); m_sender->VSendGetBarsHistoryMetaInfoFile(waiter.Id(), symbol, priceType, period); string result = waiter.WaitForResponse(); return result; }
void wait_generic_container(Container &c) { multiple_waiter_t waiter(Type, c.size()); std::vector<multiple_wait_callback_t> waits; waits.reserve(c.size()); for (auto &&item : c) { waits.emplace_back(item, &waiter); } waiter.wait(); }
CFxSessionInfo CClient::GetSessionInfo(const size_t timeoutInMilliseconds) { Waiter<CFxSessionInfo> waiter(static_cast<uint32>(timeoutInMilliseconds), cExternalSynchCall, *this); m_sender->VSendGetSessionInfo(waiter.Id()); CFxSessionInfo result = waiter.WaitForResponse(); return result; }
CFxFileChunk CClient::GetFileChunk(const string& fileId, uint32 chunkId, const size_t timeoutInMilliseconds) { Waiter<CFxFileChunk> waiter(static_cast<uint32>(timeoutInMilliseconds), cExternalSynchCall, fileId, *this); m_sender->VSendGetFileChunk(waiter.Id(), fileId, chunkId); CFxFileChunk result = waiter.WaitForResponse(); return result; }
HRESULT CDataFeed::UnsubscribeQuotes(const vector<string>& symbols, uint32 timeoutInMilliseconds) { Waiter<HRESULT> waiter(timeoutInMilliseconds, cExternalSynchCall, *this); m_sender->VSendUnsubscribeQuotes(waiter.Id(), symbols); HRESULT result = waiter.WaitForResponse(); return result; }
int ConnectionWaiter::openDialog(const QString &title, const QString &labelText, int targetDeviceCount, int timeout, QWidget *parent, Qt::WindowFlags flags) { TimedDialog dlg(title, labelText, timeout / 1000, parent, flags); ConnectionWaiter waiter(targetDeviceCount, timeout, parent); connect(&dlg, SIGNAL(canceled()), &waiter, SLOT(cancel())); connect(&waiter, SIGNAL(timeChanged(int)), &dlg, SLOT(perform())); return waiter.exec(); }
s32 sys_rwlock_rlock(PPUThread& ppu, u32 rw_lock_id, u64 timeout) { sys_rwlock.Log("sys_rwlock_rlock(rw_lock_id=0x%x, timeout=0x%llx)", rw_lock_id, timeout); const u64 start_time = get_system_time(); LV2_LOCK; const auto rwlock = idm::get<lv2_rwlock_t>(rw_lock_id); if (!rwlock) { return CELL_ESRCH; } if (!rwlock->writer && rwlock->wsq.empty()) { if (!++rwlock->readers) { throw EXCEPTION("Too many readers"); } return CELL_OK; } // add waiter; protocol is ignored in current implementation sleep_queue_entry_t waiter(ppu, rwlock->rsq); while (!ppu.unsignal()) { CHECK_EMU_STATUS; if (timeout) { const u64 passed = get_system_time() - start_time; if (passed >= timeout) { return CELL_ETIMEDOUT; } ppu.cv.wait_for(lv2_lock, std::chrono::microseconds(timeout - passed)); } else { ppu.cv.wait(lv2_lock); } } if (rwlock->writer || !rwlock->readers) { throw EXCEPTION("Unexpected"); } return CELL_OK; }
NTSTATUS COMPLETION_PORT_IMPL::Remove(ULONG& key, ULONG& value, NTSTATUS& status, ULONG& info, PLARGE_INTEGER timeout) { // try remove the completion entry first COMPLETION_PACKET *packet = queue.Head(); if (!packet) { // queue thread here COMPLETION_WAITER waiter(Current); waiter.Stop( waiter_list, timeout ); packet = waiter.GetPacket(); } // this thread must be active... don't block ourselves else if (RUNLIST_ENTRY::NumActiveThreads() > num_threads ) { // there's a packet ready but the system, is busy // a completion port isn't a FIFO - leave the packt alone // wait for idle, then remove the packet PortWaitIdle(); COMPLETION_WAITER waiter(Current); waiter.Stop( waiter_list, timeout ); //if (queue.empty() && IsLinked()) //waiting_thread_ports.unlink( this ); packet = waiter.GetPacket(); } else { // there's enough free threads to run, and there's a packet waiting // we're ready to go queue.Unlink( packet ); } if (!packet) return STATUS_TIMEOUT; key = packet->key; value = packet->value; status = packet->status; info = packet->info; delete packet; return STATUS_SUCCESS; }
HRESULT CFxTradeTransactionReportIterator::RequestReports(const bool subscribe, const string& position, const uint32 timeoutInMilliseconds) { Waiter<pair<int32, bool> > waiter(timeoutInMilliseconds, m_waiter, *m_dataTrade); ISender& sender = m_dataTrade->Sender(); sender.VSendGetTradeTransactionReportsAndSubscribeToNotifications(waiter.Id(), m_direction, subscribe, m_from, m_to, m_preferedBufferSize, position); pair<int32, bool> response = waiter.WaitForResponse(); m_reportsNumber = response.first; m_endOfStream = response.second; return S_OK; }
HRESULT CDataFeed::SubscribeToQuotes(const vector<string>& symbols, int32 depth, uint32 timeoutInMilliseconds) { Waiter<HRESULT> waiter(timeoutInMilliseconds, cExternalSynchCall, *this); m_sender->VSendSubscribeToQuotes(waiter.Id(), symbols, depth); CFxEventInfo info; HRESULT result = waiter.WaitForResponse(info); if (FAILED(result)) { throw CRejectException(info.Message, result); } return result; }
void CDataTrade::DeleteOrder(const string& /*operationId*/, const string& orderId, const string& clientId, FxTradeRecordSide side, size_t timeoutInMilliseconds) { Waiter<CFxExecutionReport> waiter(static_cast<uint32>(timeoutInMilliseconds), cExternalSynchCall, *this); m_sender->VSendDeleteOrder(waiter.Id(), orderId, clientId, side); CFxEventInfo info; CFxExecutionReport executionReport = waiter.WaitForResponse(info); if (FxOrderStatus_Rejected == executionReport.OrderStatus) { throw CRejectException(executionReport.Text, executionReport.RejectReason); } }