int ThreadData::recv(char* data, size_t datalen) { NETLIBBUFFER nlb = { data, (int)datalen, 0 }; if (!proto->usingGateway) { resetTimeout(); NETLIBSELECT nls = { 0 }; nls.cbSize = sizeof(nls); nls.dwTimeout = 1000; nls.hReadConns[0] = s; for (;;) { int ret = CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls); if (ret < 0) { proto->debugLogA("Connection abortively closed, error %d", WSAGetLastError()); return ret; } else if (ret == 0) { if (isTimeout()) return 0; } else break; } } LBL_RecvAgain: int ret = CallService(MS_NETLIB_RECV, (WPARAM)s, (LPARAM)&nlb); if (ret == 0) { proto->debugLogA("Connection closed gracefully"); return 0; } if (ret < 0) { proto->debugLogA("Connection abortively closed, error %d", WSAGetLastError()); return ret; } if (proto->usingGateway) { if (ret == 1 && *data == 0) { if (sessionClosed || isTimeout()) return 0; if ((mGatewayTimeout += 2) > 20) mGatewayTimeout = 20; CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(s), mGatewayTimeout); goto LBL_RecvAgain; } else { resetTimeout(); mGatewayTimeout = 1; CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(s), mGatewayTimeout); } } return ret; }
bool ThreadData::isTimeout(void) { bool res = false; if (mWaitPeriod >= clock()) return false; if (mIsMainThread) { res = !proto->usingGateway; } else if (mJoinedContactsWLID.getCount() <= 1 || mChatID[0] == 0) { MCONTACT hContact = getContactHandle(); if (mJoinedContactsWLID.getCount() == 0 || termPending) res = true; else if (proto->p2p_getThreadSession(hContact, mType) != NULL) res = false; else if (mType == SERVER_SWITCHBOARD) { res = MSN_MsgWndExist(hContact); if (res) { WORD status = proto->getWord(hContact, "Status", ID_STATUS_OFFLINE); if ((status == ID_STATUS_OFFLINE || status == ID_STATUS_INVISIBLE || proto->m_iStatus == ID_STATUS_INVISIBLE)) res = false; } } else res = true; } if (res) { bool sbsess = mType == SERVER_SWITCHBOARD; proto->debugLogA("Dropping the idle %s due to inactivity", sbsess ? "switchboard" : "p2p"); if (!sbsess || termPending) return true; if (proto->getByte("EnableSessionPopup", 0)) { MCONTACT hContact = NULL; if (mJoinedContactsWLID.getCount()) hContact = proto->MSN_HContactFromEmail(mJoinedContactsWLID[0]); else if (mInitialContactWLID) hContact = proto->MSN_HContactFromEmail(mInitialContactWLID); if (hContact) proto->MSN_ShowPopup(hContact, TranslateT("Chat session dropped due to inactivity"), 0); } sendTerminate(); resetTimeout(true); } else resetTimeout(); return false; }
bool DetermineAuthTypeJob::finished() { QUrl redirection = reply()->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); qDebug() << Q_FUNC_INFO << redirection.toString(); if (_redirects >= maxRedirects()) { redirection.clear(); } if ((reply()->error() == QNetworkReply::AuthenticationRequiredError) || redirection.isEmpty()) { emit authType(WizardCommon::HttpCreds); } else if (redirection.toString().endsWith(account()->davPath())) { // do a new run _redirects++; resetTimeout(); setReply(getRequest(redirection)); setupConnections(reply()); return false; // don't discard } else { QRegExp shibbolethyWords("SAML|wayf"); shibbolethyWords.setCaseSensitivity(Qt::CaseInsensitive); if (redirection.toString().contains(shibbolethyWords)) { emit authType(WizardCommon::Shibboleth); } else { // TODO: Send an error. // eh? emit authType(WizardCommon::HttpCreds); } } return true; }
void MySQLClient::setup(Host& host, const string& user, const string& password, const string& db) //Setup connection, make DNS Req if necessary { init(); //Initialize client in known state, create socket resetTimeout(); m_host = host; if(!host.getPort()) host.setPort( MYSQL_PORT ); //Default port m_user = user; m_password = password; m_db = db; if( !host.getIp().isNull() ) { connect(); } else //Need to do a DNS Query... { DBG("DNS Query...\n"); m_pDnsReq = new DNSRequest(); m_pDnsReq->setOnReply(this, &MySQLClient::onDNSReply); m_pDnsReq->resolve(&m_host); DBG("MySQLClient : DNSRequest %p\n", m_pDnsReq); } }
void MySQLClient::connect() //Start Connection { resetTimeout(); DBG("Connecting...\n"); m_pTCPSocket->connect(m_host); m_packetId = 0; }
int Socket::recvPacket() { int i = recv(mSocket, (char*)mRecvBuf, RECV_BUF_SIZE, 0); if (i > 0) { resetTimeout(); return i; } else if (i == -1) { int err; #ifdef _WIN32 err = WSAGetLastError(); if (err != WSAEWOULDBLOCK) #else err = errno; if (err != EWOULDBLOCK) #endif { setFatalErrorMessageFormat(mEQNet, "recvPacket: error %i", err); } } return -1; }
ThreadData::ThreadData() { memset(&mInitialContactWLID, 0, sizeof(ThreadData) - 2 * sizeof(STRLIST)); mGatewayTimeout = 2; resetTimeout(); hWaitEvent = CreateSemaphore(NULL, 0, MSN_PACKETS_COMBINE, NULL); mData = (char*)mir_calloc((mDataSize=8192)+1); }
void HeaderServerChannel::Stream::notifyReceive(unique_ptr<IOBuf>&& buf) { if (!manager_->isDone()) { manager_->notifyReceive(std::move(buf)); } if (!manager_->isDone()) { resetTimeout(); } deleteThisIfNecessary(); }
void MySQLClient::onTCPSocketEvent(TCPSocketEvent e) { DBG("Event %d in MySQLClient::onTCPSocketEvent()\n", e); if(m_closed) { DBG("WARN: Discarded\n"); return; } switch(e) { case TCPSOCKET_READABLE: //Incoming data resetTimeout(); if(m_state == MYSQL_HANDSHAKE) handleHandshake(); else if(m_state == MYSQL_AUTH) handleAuthResult(); else if(m_state == MYSQL_COMMANDS) handleCommandResult(); break; case TCPSOCKET_WRITEABLE: //We can send data resetTimeout(); break; case TCPSOCKET_CONNECTED: //Connected, wait for handshake packet resetTimeout(); break; case TCPSOCKET_CONTIMEOUT: case TCPSOCKET_CONRST: case TCPSOCKET_CONABRT: case TCPSOCKET_ERROR: DBG("Connection error.\n"); onResult(MYSQL_CONN); case TCPSOCKET_DISCONNECTED: //There might still be some data available for reading //So if we are in a reading state, do not close the socket yet if(m_state != MYSQL_CLOSED) { onResult(MYSQL_CONN); } DBG("Connection closed by remote host.\n"); break; } }
bool CheckServerJob::finished() { account()->setSslConfiguration(reply()->sslConfiguration()); // ### the qDebugs here should be exported via displayErrors() so they // ### can be presented to the user if the job executor has a GUI QUrl requestedUrl = reply()->request().url(); QUrl redirectUrl = reply()->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); if (!redirectUrl.isEmpty()) { _redirectCount++; if (requestedUrl.scheme() == QLatin1String("https") && redirectUrl.scheme() == QLatin1String("http")) { qDebug() << Q_FUNC_INFO << "HTTPS->HTTP downgrade detected!"; } else if (requestedUrl == redirectUrl || _redirectCount >= maxRedirects()) { qDebug() << Q_FUNC_INFO << "Redirect loop detected!"; } else { resetTimeout(); setReply(getRequest(redirectUrl)); setupConnections(reply()); return false; } } // The serverInstalls to /owncloud. Let's try that if the file wasn't found // at the original location if ((reply()->error() == QNetworkReply::ContentNotFoundError) && (!_subdirFallback)) { _subdirFallback = true; setPath(QLatin1String(owncloudDirC)+QLatin1String(statusphpC)); start(); qDebug() << "Retrying with" << reply()->url(); return false; } bool success = false; QByteArray body = reply()->readAll(); if( body.isEmpty() ) { emit instanceNotFound(reply()); } else { QVariantMap status = QtJson::parse(QString::fromUtf8(body), success).toMap(); // empty or invalid response if (!success || status.isEmpty()) { qDebug() << "status.php from server is not valid JSON!"; } qDebug() << "status.php returns: " << status << " " << reply()->error() << " Reply: " << reply(); if( status.contains("installed") && status.contains("version") && status.contains("versionstring") ) { emit instanceFound(reply()->url(), status); } else { qDebug() << "No proper answer on " << requestedUrl; emit instanceNotFound(reply()); } } return true; }
void BufferSender::setBuffer( BufferType& buffer ) { MC2_ASSERT( m_impl->state == READY || m_impl->state == DONE ); MC2_ASSERT( buffer.size() != 0 ); m_impl->setBuffer( buffer ); m_impl->state = SENDING; resetTimeout(); }
void PollJob::start() { setTimeout(120 * 1000); QUrl accountUrl = account()->url(); QUrl finalUrl = QUrl::fromUserInput(accountUrl.scheme() + QLatin1String("://") + accountUrl.authority() + (path().startsWith('/') ? QLatin1String("") : QLatin1String("/")) + path()); setReply(getRequest(finalUrl)); setupConnections(reply()); connect(reply(), SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(resetTimeout())); AbstractNetworkJob::start(); }
void AbstractNetworkJob::slotFinished() { _timer.stop(); if( _reply->error() == QNetworkReply::SslHandshakeFailedError ) { qDebug() << "SslHandshakeFailedError: " << reply()->errorString() << " : can be caused by a webserver wanting SSL client certificates"; } if( _reply->error() != QNetworkReply::NoError ) { qDebug() << Q_FUNC_INFO << _reply->error() << _reply->errorString() << _reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); if (_reply->error() == QNetworkReply::ProxyAuthenticationRequiredError) { qDebug() << Q_FUNC_INFO << _reply->rawHeader("Proxy-Authenticate"); } emit networkError(_reply); } // get the Date timestamp from reply _responseTimestamp = _reply->rawHeader("Date"); _duration = _durationTimer.elapsed(); if (_followRedirects) { // ### the qWarnings here should be exported via displayErrors() so they // ### can be presented to the user if the job executor has a GUI QUrl requestedUrl = reply()->request().url(); QUrl redirectUrl = reply()->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); if (!redirectUrl.isEmpty()) { _redirectCount++; if (requestedUrl.scheme() == QLatin1String("https") && redirectUrl.scheme() == QLatin1String("http")) { qWarning() << this << "HTTPS->HTTP downgrade detected!"; } else if (requestedUrl == redirectUrl || _redirectCount >= maxRedirects()) { qWarning() << this << "Redirect loop detected!"; } else { resetTimeout(); setReply(getRequest(redirectUrl)); setupConnections(reply()); return; } } } AbstractCredentials *creds = _account->credentials(); if (!creds->stillValid(_reply) && ! _ignoreCredentialFailure) { _account->handleInvalidCredentials(); } bool discard = finished(); if (discard) { deleteLater(); } }
int ThreadData::send(const char data[], size_t datalen) { NETLIBBUFFER nlb = { (char*)data, (int)datalen, 0 }; resetTimeout(); if (proto->usingGateway && !(mType == SERVER_FILETRANS || mType == SERVER_P2P_DIRECT)) { mGatewayTimeout = 2; CallService(MS_NETLIB_SETPOLLINGTIMEOUT, WPARAM(s), mGatewayTimeout); } int rlen = CallService(MS_NETLIB_SEND, (WPARAM)s, (LPARAM)&nlb); if (rlen == SOCKET_ERROR) { // should really also check if sendlen is the same as datalen proto->debugLogA("Send failed: %d", WSAGetLastError()); return FALSE; } return TRUE; }
HeaderServerChannel::Stream::Stream( HeaderServerChannel* channel, uint32_t sequenceId, const std::vector<uint16_t>& trans, const std::map<std::string, std::string>& headers, std::chrono::milliseconds timeout, std::unique_ptr<folly::IOBuf>&& buffer, std::unique_ptr<StreamManager>&& manager, MessageChannel::SendCallback* sendCallback) : channel_(channel), sequenceId_(sequenceId), transforms_(trans), headers_(headers), timeout_(timeout), buffer_(std::move(buffer)), manager_(std::move(manager)), sendCallback_(sendCallback), hasOutstandingSend_(true) { CHECK(manager_); manager_->setChannelCallback(this); resetTimeout(); }
void MohawkEngine_CSTime::eventIdle() { bool done = false; while (_events.size() && !done && true /* TODO: !_options->getState() */) { _lastTimeout = 0xffffffff; bool advanceQueue = true; bool processEvent = true; CSTimeEvent &event = _events.front(); switch (event.type) { case kCSTimeEventCharPlayNIS: if (_NISRunning) { CSTimeChar *chr = _case->getCurrScene()->getChar(event.param1); if (chr->NISIsDone()) { chr->removeNIS(); _NISRunning = false; chr->setupAmbientAnims(true); _events.pop_front(); processEvent = false; } else { done = true; } } else { advanceQueue = false; } break; case kCSTimeEventNewScene: if (_processingEvent) { processEvent = false; _events.pop_front(); _processingEvent = false; // FIXME: check skip global, if set: // stopMusic(), stopEnvironmentSound(), set scene to _nextSceneId, // set scene state to 1, set state to idle loop } else { triggerEvent(event); done = true; _processingEvent = true; } break; case kCSTimeEventCharStartFlapping: assert(_case->getCurrScene()->_activeChar); switch (_case->getCurrScene()->_activeChar->_flappingState) { case 0xffff: // FIXME: check skip global, if set, processEvent = false and pop event advanceQueue = false; break; case 0: _case->getCurrScene()->_activeChar->_flappingState = 0xffff; _events.pop_front(); processEvent = false; break; default: done = true; break; } break; case kCSTimeEventCharSomeNIS55: // This is like kCSTimeEventCharPlayNIS, only using a different flag variable. if (_processingNIS55) { CSTimeChar *chr = _case->getCurrScene()->getChar(event.param1); if (chr->NISIsDone()) { chr->removeNIS(); _processingNIS55 = false; chr->setupAmbientAnims(true); _events.pop_front(); processEvent = false; } else { done = true; } } else { advanceQueue = false; } break; default: break; } if (!done && processEvent) { _interface->cursorSetWaitCursor(); triggerEvent(event); if (advanceQueue) _events.pop_front(); } if (!_events.size()) { Common::Point pos = _system->getEventManager()->getMousePos(); if (_interface->_sceneRect.contains(pos)) _case->getCurrScene()->setCursorForCurrentPoint(); else _interface->setCursorForCurrentPoint(); _interface->mouseMove(pos); resetTimeout(); } } }
int start() { resetTimeout(); // if (!exceptionIsActive) log.info() << "step '" << name << "' started"; BaseSequence::action(); return 0; }
void ping(const Ping& event) { if (connected && is_valid(event)) { resetTimeout(); } }
void AbstractNetworkJob::slotFinished() { _timer.stop(); if (_reply->error() == QNetworkReply::SslHandshakeFailedError) { qCWarning(lcNetworkJob) << "SslHandshakeFailedError: " << errorString() << " : can be caused by a webserver wanting SSL client certificates"; } if (_reply->error() != QNetworkReply::NoError) { if (!_ignoreCredentialFailure || _reply->error() != QNetworkReply::AuthenticationRequiredError) { qCWarning(lcNetworkJob) << _reply->error() << errorString() << _reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); if (_reply->error() == QNetworkReply::ProxyAuthenticationRequiredError) { qCWarning(lcNetworkJob) << _reply->rawHeader("Proxy-Authenticate"); } } emit networkError(_reply); } // get the Date timestamp from reply _responseTimestamp = _reply->rawHeader("Date"); QUrl requestedUrl = reply()->request().url(); QUrl redirectUrl = reply()->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); if (_followRedirects && !redirectUrl.isEmpty()) { // Redirects may be relative if (redirectUrl.isRelative()) redirectUrl = requestedUrl.resolved(redirectUrl); // For POST requests where the target url has query arguments, Qt automatically // moves these arguments to the body if no explicit body is specified. // This can cause problems with redirected requests, because the redirect url // will no longer contain these query arguments. if (reply()->operation() == QNetworkAccessManager::PostOperation && requestedUrl.hasQuery() && !redirectUrl.hasQuery() && !_requestBody) { qCWarning(lcNetworkJob) << "Redirecting a POST request with an implicit body loses that body"; } // ### some of the qWarnings here should be exported via displayErrors() so they // ### can be presented to the user if the job executor has a GUI QByteArray verb = requestVerb(*reply()); if (requestedUrl.scheme() == QLatin1String("https") && redirectUrl.scheme() == QLatin1String("http")) { qCWarning(lcNetworkJob) << this << "HTTPS->HTTP downgrade detected!"; } else if (requestedUrl == redirectUrl || _redirectCount + 1 >= maxRedirects()) { qCWarning(lcNetworkJob) << this << "Redirect loop detected!"; } else if (_requestBody && _requestBody->isSequential()) { qCWarning(lcNetworkJob) << this << "cannot redirect request with sequential body"; } else if (verb.isEmpty()) { qCWarning(lcNetworkJob) << this << "cannot redirect request: could not detect original verb"; } else { emit redirected(_reply, redirectUrl, _redirectCount); // The signal emission may have changed this value if (_followRedirects) { _redirectCount++; // Create the redirected request and send it qCInfo(lcNetworkJob) << "Redirecting" << verb << requestedUrl << redirectUrl; resetTimeout(); if (_requestBody) { _requestBody->seek(0); } sendRequest( verb, redirectUrl, reply()->request(), _requestBody); return; } } } AbstractCredentials *creds = _account->credentials(); if (!creds->stillValid(_reply) && !_ignoreCredentialFailure) { _account->handleInvalidCredentials(); } bool discard = finished(); if (discard) { qCDebug(lcNetworkJob) << "Network job" << metaObject()->className() << "finished for" << path(); deleteLater(); } }