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; }
void SyncSourceFeedback::run() { Client::initThread("SyncSourceFeedbackThread"); OperationContextImpl txn; bool positionChanged = false; bool handshakeNeeded = false; ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); while (!inShutdown()) { // TODO(spencer): Remove once legacy repl coordinator is gone. { boost::unique_lock<boost::mutex> lock(_mtx); while (!_positionChanged && !_handshakeNeeded && !_shutdownSignaled) { _cond.wait(lock); } if (_shutdownSignaled) { break; } positionChanged = _positionChanged; handshakeNeeded = _handshakeNeeded; _positionChanged = false; _handshakeNeeded = false; } MemberState state = replCoord->getCurrentMemberState(); if (state.primary() || state.fatal() || state.startup()) { continue; } const Member* target = BackgroundSync::get()->getSyncTarget(); if (_syncTarget != target) { _resetConnection(); _syncTarget = target; } if (!hasConnection()) { // fix connection if need be if (!target) { sleepmillis(500); continue; } if (!_connect(&txn, target->fullName())) { sleepmillis(500); continue; } } if (handshakeNeeded) { if (!replHandshake(&txn)) { boost::unique_lock<boost::mutex> lock(_mtx); _handshakeNeeded = true; continue; } } if (positionChanged) { if (!updateUpstream(&txn)) { boost::unique_lock<boost::mutex> lock(_mtx); _positionChanged = true; } } } cc().shutdown(); }
void ConnectionEditor::updateConnectButton() { bool itemsSelected = signalBox->currentItem() != -1 && slotBox->currentItem() != -1; bool notConnected = !itemsSelected || !hasConnection(m_sender->name(), signalBox->currentText(), m_receiver->name(), slotBox->currentText()); bool connectionAllowed = notConnected && checkConnectArgs(MetaDataBase::normalizeSlot(signalBox->currentText()).latin1(), m_receiver, MetaDataBase::normalizeSlot(slotBox->currentText()).latin1()); connectButton->setEnabled(itemsSelected && notConnected && connectionAllowed); }
void Room::removeConnection(RoomDirection direction) { if (hasConnection(direction)) { Room * opposite = this->connected[direction]; RoomDirection oppositeDirection = getOpposite(direction); if (opposite->hasConnection(oppositeDirection)) opposite->setFromOpposite(oppositeDirection, nullptr); } this->connected[direction] = nullptr; }
void SyncSourceFeedback::run() { Client::initThread("SyncSourceFeedback"); ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); while (true) { // breaks once _shutdownSignaled is true { stdx::unique_lock<stdx::mutex> lock(_mtx); while (!_positionChanged && !_shutdownSignaled) { if (_cond.wait_for(lock, _keepAliveInterval) == stdx::cv_status::timeout) { break; } } if (_shutdownSignaled) { break; } _positionChanged = false; } auto txn = cc().makeOperationContext(); MemberState state = replCoord->getMemberState(); if (state.primary() || state.startup()) { _resetConnection(); continue; } const HostAndPort target = BackgroundSync::get()->getSyncTarget(); if (_syncTarget != target) { _resetConnection(); _syncTarget = target; } if (!hasConnection()) { // fix connection if need be if (target.empty()) { sleepmillis(500); stdx::unique_lock<stdx::mutex> lock(_mtx); _positionChanged = true; continue; } if (!_connect(txn.get(), target)) { sleepmillis(500); stdx::unique_lock<stdx::mutex> lock(_mtx); _positionChanged = true; continue; } } Status status = updateUpstream(txn.get()); if (!status.isOK()) { sleepmillis(500); stdx::unique_lock<stdx::mutex> lock(_mtx); _positionChanged = true; } } }
void sendMsg(unsigned id, F f, O o, Message msg) { if (hasConnection(id)) { PtrBuffer buffer = getSendBuffer(id); ostream os(&(*buffer)); os << msg.serialize() << '\0'; async_write(*getSocket(id), *buffer, bind(&ConnectionList::_sendMsg<F, O>, this, id, f, o, msg, _1, _2)); } }
void _recvMsg(unsigned id, F f, O o, const error_code& ec, size_t bytes) { if (ec == error::eof || bytes < 1) (o->*f)(id, Message(Message::MSG_EOF)); else { if (hasConnection(id)) { PtrBuffer buffer = getRecvBuffer(id); Message msg(buffer); (o->*f)(id, msg); } } }
void Client::readyForUse() { Connection *connection = qobject_cast<Connection *>(sender()); if (!connection || hasConnection(connection->peerAddress(), connection->peerPort())) return; connect(connection, SIGNAL(newMessage(QString,QString)), this, SIGNAL(newMessage(QString,QString))); connect(connection, SIGNAL(newCode(QString,QString)), this, SIGNAL(newCode(QString,QString))); peers.insert(connection->peerAddress(), connection); QString nick = connection->name(); if (!nick.isEmpty()) emit newParticipant(nick); }
bool SyncSourceFeedback::_connect(OperationContext* txn, const HostAndPort& host) { if (hasConnection()) { return true; } log() << "replset setting syncSourceFeedback to " << host.toString() << rsLog; _connection.reset(new DBClientConnection(false, 0, OplogReader::tcp_timeout)); string errmsg; try { if (!_connection->connect(host, errmsg) || (getGlobalAuthorizationManager()->isAuthEnabled() && !replAuthenticate())) { _resetConnection(); log() << "repl: " << errmsg << endl; return false; } } catch (const DBException& e) { log() << "Error connecting to " << host.toString() << ": " << e.what(); _resetConnection(); return false; } return hasConnection(); }
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; } } } } }
Room * Room::moveTo(RoomDirection dir) { if (hasConnection(dir)) { connected[dir]->setVisiting(true); connected[dir]->setVisited(); this->setVisiting(false); return connected[dir]; } else { return this; } }
/** * startUpMethod function * Old login funtion */ void TwitterApp::startUpMethod() { if (hasConnection()) { std::string tempname; if (userID[0] == '@') { tempname = userID.substr(1, userID.length()); } else { tempname = userID; } rapidjson::Document temp = (TwitterApp::getInstance()->getTwitter()->showUser(tempname, false)); userID = temp["id_str"].GetString(); profileContentArea->setCurProfile(userID); changeState(WALL); } }
bool SyncSourceFeedback::_connect(const std::string& hostName) { if (hasConnection()) { return true; } _connection.reset(new DBClientConnection(false, 0, OplogReader::tcp_timeout)); string errmsg; if (!_connection->connect(hostName.c_str(), errmsg) || (AuthorizationManager::isAuthEnabled() && !replAuthenticate(true))) { resetConnection(); log() << "repl: " << errmsg << endl; return false; } if (!replHandshake()) { if (!supportsUpdater()) { return connectOplogReader(hostName); } return false; } return true; }
void ConnectionEditor::connectClicked() { if (signalBox->currentItem() == -1 || slotBox->currentItem() == -1) return; if (hasConnection(m_sender->name(), signalBox->currentText(), m_receiver->name(), slotBox->currentText())) return; MetaDataBase::Connection conn; conn.sender = m_sender; conn.signal = signalBox->currentText(); conn.slot = slotBox->currentText(); conn.receiver = m_receiver; KListViewItem *i = new KListViewItem(connectionView, m_sender->name(), conn.signal, m_receiver->name(), conn.slot); i->setPixmap(0, PixmapChooser::loadPixmap("connecttool.xpm")); connectionView->setCurrentItem(i); connectionView->setSelected(i, true); m_connections.insert(i, conn); connectButton->setEnabled(false); updateDisconnectButton(); }
/*************************************************************************** * connectRooms * Parameter: roomA - the first room * roomB - the second room * Description: This function create a door/connection between two room. * This will only generate a connection if the rooms have available * space to add dorrs (both must have it), as well as be different rooms. ***************************************************************************/ void connectRooms( Room* roomA, Room* roomB ) { // make sure we are not over the limit if( roomA->doorCount >= MAX_DOORS_PER_ROOM || roomB->doorCount >= MAX_DOORS_PER_ROOM ) { return; } //check if it already has connection if( hasConnection( roomA, roomB ) ) { return; } //if no connection exist, then connect it roomA->doors_list[roomA->doorCount] = roomB; // add roomB to roomA list roomA->doorCount++; roomB->doors_list[roomB->doorCount] = roomA; // add roomA to roomB list roomB->doorCount++; return; }
int irc_connect_generic(irc_session_t * session, const char * server, unsigned short port, const char * server_password, const char * nick, const char * username, const char * realname, int protocol_family) { struct irc_addr_t **addresses; int numAddresses = 0; if (!server || !nick) { session->lasterror = LIBIRC_ERR_INVAL; return 1; } if (session->state != LIBIRC_STATE_INIT) { session->lasterror = LIBIRC_ERR_STATE; return 1; } // Free the strings if defined; may be the case when the session is reused after the connection fails free_ircsession_strings(session); if (server[0] == SSL_PREFIX) { #if defined (ENABLE_SSL) server++; session->flags |= SESSIONFL_SSL_CONNECTION; #else session->lasterror = LIBIRC_ERR_SSL_NOT_SUPPORTED; return 1; #endif } if (username) session->username = strdup(username); if (server_password) session->server_password = strdup(server_password); if (realname) session->realname = strdup(realname); session->nick = strdup(nick); session->server = strdup(server); addresses = resolve_hostname_by_dns(session->server, &numAddresses, protocol_family); if (addresses == NULL) { session->lasterror = LIBIRC_ERR_RESOLV; return 1; } int selectedAddress = rand_range(0, numAddresses - 1); // and connect to the IRC server for (; addresses[selectedAddress] != NULL; selectedAddress++) { struct irc_addr_t *currentAddress = addresses[selectedAddress]; int ret = -1; if (currentAddress->family == AF_INET) ret = try_to_connect_ipv4(session, currentAddress, port); #if defined (ENABLE_IPV6) else if (currentAddress->family == AF_INET6) ret = try_to_connect_ipv6(session, currentAddress, port); #endif if (ret == -1) { goto err_out; } if (hasConnection(session)) { break; } else { socket_close(&session->sock); } } if (addresses[selectedAddress] == NULL) { session->lasterror = LIBIRC_ERR_CONNECT; goto err_out; } logprintf(LOG_INFO, "Connection successful!"); free_addresses(addresses); session->state = LIBIRC_STATE_CONNECTING; if (protocol_family == AF_INET6) session->flags |= SESSIONFL_USES_IPV6; return 0; err_out: free_addresses(addresses); return 1; }
void SyncSourceFeedback::run() { Client::initThread("SyncSourceFeedbackThread"); bool sleepNeeded = false; while (true) { if (sleepNeeded) { sleepmillis(500); sleepNeeded = false; } { boost::unique_lock<boost::mutex> lock(_mtx); while (!_positionChanged && !_handshakeNeeded) { _cond.wait(lock); } if (theReplSet->isPrimary()) { _positionChanged = false; _handshakeNeeded = false; continue; } const Member* target = replset::BackgroundSync::get()->getSyncTarget(); boost::unique_lock<boost::mutex> connlock(_connmtx); if (_syncTarget != target) { resetConnection(); _syncTarget = target; } if (!hasConnection()) { // fix connection if need be if (!target) { sleepNeeded = true; continue; } if (!_connect(target->fullName())) { sleepNeeded = true; continue; } else if (!supportsUpdater()) { _handshakeNeeded = false; _positionChanged = false; continue; } } if (_handshakeNeeded) { if (!replHandshake()) { _handshakeNeeded = true; continue; } else { _handshakeNeeded = false; _positionChanged = true; } } if (_positionChanged) { if (!updateUpstream()) { // no need to set _handshakeNeeded to true as a failed updateUpstream() call // will call resetConnection() and when the new connection is established // the handshake process will be run _positionChanged = true; continue; } else { _positionChanged = false; } } } } }
void recvMsg(unsigned id, F f, O o) { if (hasConnection(id)) async_read_until(*getSocket(id), *getRecvBuffer(id), '\0', bind(&ConnectionList::_recvMsg<F, O>, this, id, f, o, _1, _2)); }