bool SyncSourceFeedback::_connect(const std::string& hostName) { if (hasConnection()) { return true; } log() << "replset setting syncSourceFeedback to " << hostName << rsLog; _connection.reset(new DBClientConnection(false, 0, OplogReader::tcp_timeout)); string errmsg; try { if (!_connection->connect(hostName.c_str(), errmsg) || (getGlobalAuthorizationManager()->isAuthEnabled() && !replAuthenticate())) { resetConnection(); log() << "repl: " << errmsg << endl; return false; } } catch (const DBException& e) { log() << "Error connecting to " << hostName << ": " << e.what(); resetConnection(); return false; } if (!replHandshake()) { if (!supportsUpdater()) { return connectOplogReader(hostName); } return false; } return true; }
bool OplogReader::connect(const HostAndPort& host) { if (conn() == NULL || _host != host) { resetConnection(); _conn = shared_ptr<DBClientConnection>(new DBClientConnection(false, tcp_timeout)); string errmsg; if (!_conn->connect(host, errmsg) || (getGlobalAuthorizationManager()->isAuthEnabled() && !replAuthenticate(_conn.get()))) { resetConnection(); log() << "repl: " << errmsg << endl; return false; } _host = host; } return true; }
bool Protocol::accept(int _timeout) { ULXR_TRACE("accept"); bool res = getConnection()->accept(_timeout); resetConnection(); return res; }
void SocksClient::sock_error(int x) { if(isOpen()) { resetConnection(); setError(ErrRead); } else { resetConnection(true); if(x == BSocket::ErrHostNotFound) setError(ErrProxyConnect); else if(x == BSocket::ErrConnectionRefused) setError(ErrProxyConnect); else if(x == BSocket::ErrRead) setError(ErrProxyNeg); } }
// Resets the sensor by a soft reset uint8_t Sensirion::softReset(void) { // Reset communication resetConnection(); //send RESET-command to sensor, return = 1 in case of no response return (putByte(REG_RESET)); }
void ClientSyncer::connectToCore(const QVariantMap &conn) { resetConnection(); coreConnectionInfo = conn; if(conn["Host"].toString().isEmpty()) { emit connectionError(tr("No Host to connect to specified.")); return; } Q_ASSERT(!_socket); #ifdef HAVE_SSL QSslSocket *sock = new QSslSocket(Client::instance()); #else if(conn["useSsl"].toBool()) { emit connectionError(tr("<b>This client is built without SSL Support!</b><br />Disable the usage of SSL in the account settings.")); return; } QTcpSocket *sock = new QTcpSocket(Client::instance()); #endif #ifndef QT_NO_NETWORKPROXY if(conn.contains("useProxy") && conn["useProxy"].toBool()) { QNetworkProxy proxy((QNetworkProxy::ProxyType)conn["proxyType"].toInt(), conn["proxyHost"].toString(), conn["proxyPort"].toUInt(), conn["proxyUser"].toString(), conn["proxyPassword"].toString()); sock->setProxy(proxy); } #endif _socket = sock; connect(sock, SIGNAL(readyRead()), this, SLOT(coreHasData())); connect(sock, SIGNAL(connected()), this, SLOT(coreSocketConnected())); connect(sock, SIGNAL(disconnected()), this, SLOT(coreSocketDisconnected())); connect(sock, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(coreSocketError(QAbstractSocket::SocketError))); connect(sock, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SIGNAL(socketStateChanged(QAbstractSocket::SocketState))); sock->connectToHost(conn["Host"].toString(), conn["Port"].toUInt()); }
void HttpConnect::sock_error(int x) { if(d->active) { resetConnection(); setError(ErrRead); } else { resetConnection(true); if(x == BSocket::ErrHostNotFound) setError(ErrProxyConnect); else if(x == BSocket::ErrConnectionRefused) setError(ErrProxyConnect); else if(x == BSocket::ErrRead) setError(ErrProxyNeg); } }
void HttpConnect::sock_delayedCloseFinished() { if(d->active) { resetConnection(); delayedCloseFinished(); } }
void SocksClient::sock_delayedCloseFinished() { if(isOpen()) { resetConnection(); delayedCloseFinished(); } }
bool OplogReader::connect(const HostAndPort& host) { if (conn() == NULL || _host != host) { resetConnection(); _conn = std::shared_ptr<DBClientConnection>( new DBClientConnection(false, durationCount<Seconds>(kSocketTimeout))); std::string errmsg; if (!_conn->connect(host, StringData(), errmsg) || !replAuthenticate(_conn.get())) { resetConnection(); error() << errmsg; return false; } _conn->setTags(transport::Session::kKeepOpen); _host = host; } return true; }
bool OplogReader::connect(const HostAndPort& host) { if (conn() == NULL || _host != host) { resetConnection(); _conn = shared_ptr<DBClientConnection>( new DBClientConnection(false, durationCount<Seconds>(kSocketTimeout))); string errmsg; if (!_conn->connect(host, errmsg) || (getGlobalAuthorizationManager()->isAuthEnabled() && !replAuthenticate(_conn.get()))) { resetConnection(); error() << errmsg << endl; return false; } _conn->port().tag |= executor::NetworkInterface::kMessagingPortKeepOpen; _host = host; } return true; }
bool OplogReader::connect(const HostAndPort& host) { if (conn() == NULL || _host != host) { resetConnection(); _conn = shared_ptr<DBClientConnection>( new DBClientConnection(false, durationCount<Seconds>(kSocketTimeout))); string errmsg; if (!_conn->connect(host, StringData(), errmsg) || !replAuthenticate(_conn.get())) { resetConnection(); error() << errmsg << endl; return false; } _conn->port().setTag(_conn->port().getTag() | executor::NetworkInterface::kMessagingPortKeepOpen); _host = host; } return true; }
void HttpProxyPost::tls_error() { #ifdef PROX_DEBUG fprintf(stderr, "HttpProxyGetStream: ssl error: %d\n", d->tls->errorCode()); #endif resetConnection(true); error(ErrConnectionRefused); // FIXME: bogus error }
bool SyncSourceFeedback::updateUpstream() { if (theReplSet->isPrimary()) { // primary has no one to update to return true; } BSONObjBuilder cmd; cmd.append("replSetUpdatePosition", 1); // create an array containing objects each member connected to us and for ourself BSONArrayBuilder array (cmd.subarrayStart("optimes")); OID myID = _me["_id"].OID(); { for (map<mongo::OID, OpTime>::const_iterator itr = _slaveMap.begin(); itr != _slaveMap.end(); ++itr) { BSONObjBuilder entry(array.subobjStart()); entry.append("_id", itr->first); entry.append("optime", itr->second); if (itr->first == myID) { entry.append("config", theReplSet->myConfig().asBson()); } else { entry.append("config", _members[itr->first]->config().asBson()); } entry.doneFast(); } } array.done(); BSONObj res; bool ok; try { ok = _connection->runCommand("admin", cmd.obj(), res); } catch (const DBException& e) { log() << "SyncSourceFeedback error sending update: " << e.what() << endl; resetConnection(); return false; } if (!ok) { log() << "SyncSourceFeedback error sending update, response: " << res.toString() <<endl; resetConnection(); return false; } return true; }
void SocksClient::requestDeny() { if(d->step != StepRequest || !d->waiting) return; // response d->waiting = false; writeData(sp_set_request(d->rhost, d->rport, RET_UNREACHABLE)); resetConnection(true); }
void HttpPoll::close() { if(d->state == 0 || d->closing) return; if(bytesToWrite() == 0) resetConnection(); else d->closing = true; }
void SocksClient::sock_connectionClosed() { if(isOpen()) { resetConnection(); emit connectionClosed(); } else { setError(ErrProxyNeg); } }
void HttpConnect::sock_connectionClosed() { if(d->active) { resetConnection(); connectionClosed(); } else { setError(ErrProxyNeg); } }
HttpProxyPost::HttpProxyPost(QObject *parent) :QObject(parent) { d = new Private(this); connect(&d->sock, SIGNAL(connected()), SLOT(sock_connected())); connect(&d->sock, SIGNAL(connectionClosed()), SLOT(sock_connectionClosed())); connect(&d->sock, SIGNAL(readyRead()), SLOT(sock_readyRead())); connect(&d->sock, SIGNAL(error(int)), SLOT(sock_error(int))); resetConnection(true); }
bool SyncSourceFeedback::connect(const Member* target) { boost::unique_lock<boost::mutex> lock(_connmtx); resetConnection(); resetOplogReaderConnection(); _syncTarget = target; if (_connect(target->fullName())) { if (!supportsUpdater()) { return true; } } return false; }
void SocksClient::init() { d = new Private(this); connect(&d->sock, SIGNAL(connected()), SLOT(sock_connected())); connect(&d->sock, SIGNAL(connectionClosed()), SLOT(sock_connectionClosed())); connect(&d->sock, SIGNAL(delayedCloseFinished()), SLOT(sock_delayedCloseFinished())); connect(&d->sock, SIGNAL(readyRead()), SLOT(sock_readyRead())); connect(&d->sock, SIGNAL(bytesWritten(qint64)), SLOT(sock_bytesWritten(qint64))); connect(&d->sock, SIGNAL(error(int)), SLOT(sock_error(int))); resetConnection(true); }
void CoreConnection::connectToCurrentAccount() { if (_authHandler) { qWarning() << Q_FUNC_INFO << "Already connected!"; return; } resetConnection(false); if (currentAccount().isInternal()) { if (Quassel::runMode() != Quassel::Monolithic) { qWarning() << "Cannot connect to internal core in client-only mode!"; return; } emit startInternalCore(); InternalPeer *peer = new InternalPeer(); _peer = peer; Client::instance()->signalProxy()->addPeer(peer); // sigproxy will take ownership emit connectToInternalCore(peer); setState(Connected); return; } _authHandler = new ClientAuthHandler(currentAccount(), this); connect(_authHandler, SIGNAL(disconnected()), SLOT(coreSocketDisconnected())); connect(_authHandler, SIGNAL(connectionReady()), SLOT(onConnectionReady())); connect(_authHandler, SIGNAL(socketError(QAbstractSocket::SocketError,QString)), SLOT(coreSocketError(QAbstractSocket::SocketError,QString))); connect(_authHandler, SIGNAL(transferProgress(int,int)), SLOT(updateProgress(int,int))); connect(_authHandler, SIGNAL(requestDisconnect(QString,bool)), SLOT(disconnectFromCore(QString,bool))); connect(_authHandler, SIGNAL(errorMessage(QString)), SIGNAL(connectionError(QString))); connect(_authHandler, SIGNAL(errorPopup(QString)), SIGNAL(connectionErrorPopup(QString)), Qt::QueuedConnection); connect(_authHandler, SIGNAL(statusMessage(QString)), SIGNAL(connectionMsg(QString))); connect(_authHandler, SIGNAL(encrypted(bool)), SIGNAL(encrypted(bool))); connect(_authHandler, SIGNAL(startCoreSetup(QVariantList)), SIGNAL(startCoreSetup(QVariantList))); connect(_authHandler, SIGNAL(coreSetupFailed(QString)), SIGNAL(coreSetupFailed(QString))); connect(_authHandler, SIGNAL(coreSetupSuccessful()), SIGNAL(coreSetupSuccess())); connect(_authHandler, SIGNAL(userAuthenticationRequired(CoreAccount*,bool*,QString)), SIGNAL(userAuthenticationRequired(CoreAccount*,bool*,QString))); connect(_authHandler, SIGNAL(handleNoSslInClient(bool*)), SIGNAL(handleNoSslInClient(bool*))); connect(_authHandler, SIGNAL(handleNoSslInCore(bool*)), SIGNAL(handleNoSslInCore(bool*))); #ifdef HAVE_SSL connect(_authHandler, SIGNAL(handleSslErrors(const QSslSocket*,bool*,bool*)), SIGNAL(handleSslErrors(const QSslSocket*,bool*,bool*))); #endif connect(_authHandler, SIGNAL(loginSuccessful(CoreAccount)), SLOT(onLoginSuccessful(CoreAccount))); connect(_authHandler, SIGNAL(handshakeComplete(RemotePeer*,Protocol::SessionState)), SLOT(onHandshakeComplete(RemotePeer*,Protocol::SessionState))); setState(Connecting); _authHandler->connectToCore(); }
HttpConnect::HttpConnect(QObject *parent) :ByteStream(parent) { d = new Private(this); connect(&d->sock, SIGNAL(connected()), SLOT(sock_connected())); connect(&d->sock, SIGNAL(connectionClosed()), SLOT(sock_connectionClosed())); connect(&d->sock, SIGNAL(delayedCloseFinished()), SLOT(sock_delayedCloseFinished())); connect(&d->sock, SIGNAL(readyRead()), SLOT(sock_readyRead())); connect(&d->sock, SIGNAL(bytesWritten(qint64)), SLOT(sock_bytesWritten(qint64))); connect(&d->sock, SIGNAL(error(int)), SLOT(sock_error(int))); resetConnection(true); }
void checkErrorOccurence(char *allMsg) { if(strstr(allMsg, "+") != NULL) { if(strstr(allMsg, "+RDII") != NULL)//in case of disconnection { stageOfConnection = 0; stageOfInit = 0; initStatus = FALSE; removeInitTimerRx = FALSE; resetConnection(); } } }
void HttpPoll::connectToHost(const QString &proxyHost, int proxyPort, const QUrl &url) { resetConnection(true); bool useSsl = false; d->port = 80; // using proxy? if(!proxyHost.isEmpty()) { d->host = proxyHost; d->port = proxyPort; d->url = url; d->use_proxy = true; } else { d->host = url.host(); if(url.port() != -1) d->port = url.port(); else if (url.scheme() == "https") { d->port = 443; useSsl = true; } #if QT_VERSION < 0x050000 d->url = url.path() + "?" + url.encodedQuery(); #else d->url.setUrl(url.path() + "?" + url.query(QUrl::FullyEncoded), QUrl::StrictMode); #endif d->use_proxy = false; } resetKey(); bool last; QString key = getKey(&last); #ifdef PROX_DEBUG fprintf(stderr, "HttpPoll: Connecting to %s:%d [%s]", d->host.latin1(), d->port, d->url.latin1()); if(d->user.isEmpty()) fprintf(stderr, "\n"); else fprintf(stderr, ", auth {%s,%s}\n", d->user.latin1(), d->pass.latin1()); #endif QPointer<QObject> self = this; syncStarted(); if(!self) return; d->state = 1; d->http.setUseSsl(useSsl); d->http.setAuth(d->user, d->pass); d->http.post(d->host, d->port, d->url, makePacket("0", key, "", QByteArray()), d->use_proxy); }
void SyncSourceFeedback::run() { Client::initThread("SyncSourceFeedbackThread"); while (true) { { boost::unique_lock<boost::mutex> lock(_mtx); while (!_positionChanged && !_handshakeNeeded) { _cond.wait(lock); } boost::unique_lock<boost::mutex> conlock(_connmtx); const Member* target = replset::BackgroundSync::get()->getSyncTarget(); if (_syncTarget != target) { resetConnection(); _syncTarget = target; } if (!hasConnection()) { // fix connection if need be if (!target) { continue; } if (!_connect(target->fullName())) { continue; } else if (!supportsUpdater()) { _handshakeNeeded = false; _positionChanged = false; continue; } } if (_handshakeNeeded) { if (!replHandshake()) { _handshakeNeeded = true; continue; } else { _handshakeNeeded = false; } } if (_positionChanged) { if (!updateUpstream()) { _positionChanged = true; continue; } else { _positionChanged = false; } } } } }
bool OplogReader::commonConnect(const string& hostName) { if( conn() == 0 ) { _conn = shared_ptr<DBClientConnection>(new DBClientConnection(false, 0, tcp_timeout)); string errmsg; if ( !_conn->connect(hostName.c_str(), errmsg) || (AuthorizationManager::isAuthEnabled() && !replAuthenticate(_conn.get(), true)) ) { resetConnection(); log() << "repl: " << errmsg << endl; return false; } } return true; }
Sensirion::Sensirion(uint8_t dataPin, uint8_t clockPin) { // Initialize private storage for library functions _pinData = dataPin; _pinClock = clockPin; _presult = NULL; // No pending measurement _stat_reg = 0x00; // Sensor status register default state // Initialize CLK signal direction // Note: All functions exit with CLK low and DAT in input mode pinMode(_pinClock, OUTPUT); // Return sensor to default state resetConnection(); // Reset communication link with sensor putByte(SOFT_RESET); // Send soft reset command }
bool OplogReader::connect(string hostName) { if( conn() == 0 ) { _conn = auto_ptr<DBClientConnection>(new DBClientConnection( false, 0, 0 /* tcp timeout */)); string errmsg; ReplInfo r("trying to connect to sync source"); if ( !_conn->connect(hostName.c_str(), errmsg) || (!noauth && !replAuthenticate(_conn.get())) || !replHandshake(_conn.get()) ) { resetConnection(); log() << "repl: " << errmsg << endl; return false; } } return true; }
bool OplogReader::commonConnect(const string& hostName, const double default_timeout) { if( conn() == 0 ) { _conn = shared_ptr<DBClientConnection>(new DBClientConnection(false, 0, default_timeout /* tcp timeout */)); string errmsg; if ( !_conn->connect(hostName.c_str(), errmsg) || (!noauth && !replAuthenticate(_conn.get(), true)) ) { resetConnection(); log() << "repl: " << errmsg << endl; return false; } } return true; }