本文整理汇总了C++中HostAndPort::isSelf方法的典型用法代码示例。如果您正苦于以下问题:C++ HostAndPort::isSelf方法的具体用法?C++ HostAndPort::isSelf怎么用?C++ HostAndPort::isSelf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HostAndPort
的用法示例。
在下文中一共展示了HostAndPort::isSelf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateReplSetMember
void PubSubSendSocket::updateReplSetMember(HostAndPort hp) {
if (!pubsubEnabled)
return;
std::map<HostAndPort, bool>::iterator member = rsMembers.find(hp);
if (!hp.isSelf() && member == rsMembers.end()) {
std::string endpoint = str::stream() << "tcp://" << hp.host()
<< ":" << hp.port() + 1234;
try {
SimpleMutex::scoped_lock lk(sendMutex);
extSendSocket->connect(endpoint.c_str());
}
catch (zmq::error_t& e) {
log() << "PubSub error connecting to replica set member." << causedBy(e);
}
// don't need to lock around the map because this is called from a locked context
rsMembers.insert(std::make_pair(hp, true));
}
else {
member->second = true;
}
}
示例2: conn
ReplSetConfig::ReplSetConfig(const HostAndPort& h) {
clear();
int level = 2;
DEV level = 0;
BSONObj cfg;
int v = -5;
try {
if( h.isSelf() ) {
;
}
else {
/* first, make sure other node is configured to be a replset. just to be safe. */
string setname = cmdLine.ourSetName();
BSONObj cmd = BSON( "replSetHeartbeat" << setname );
int theirVersion;
BSONObj info;
log() << "trying to contact " << h.toString() << rsLog;
bool ok = requestHeartbeat(setname, "", h.toString(), info, -2, theirVersion);
if( info["rs"].trueValue() ) {
// yes, it is a replicate set, although perhaps not yet initialized
}
else {
if( !ok ) {
log() << "replSet TEMP !ok heartbeating " << h.toString() << " on cfg load" << rsLog;
if( !info.isEmpty() )
log() << "replSet info " << h.toString() << " : " << info.toString() << rsLog;
return;
}
{
stringstream ss;
ss << "replSet error: member " << h.toString() << " is not in --replSet mode";
msgassertedNoTrace(13260, ss.str().c_str()); // not caught as not a user exception - we want it not caught
//for python err# checker: uassert(13260, "", false);
}
}
}
v = -4;
unsigned long long count = 0;
try {
ScopedConn conn(h.toString());
v = -3;
cfg = conn.findOne(rsConfigNs, Query()).getOwned();
count = conn.count(rsConfigNs);
}
catch ( DBException& ) {
if ( !h.isSelf() ) {
throw;
}
// on startup, socket is not listening yet
DBDirectClient cli;
cfg = cli.findOne( rsConfigNs, Query() ).getOwned();
count = cli.count(rsConfigNs);
}
if( count > 1 )
uasserted(13109, str::stream() << "multiple rows in " << rsConfigNs << " not supported host: " << h.toString());
if( cfg.isEmpty() ) {
version = EMPTYCONFIG;
return;
}
version = -1;
}
catch( DBException& e) {
version = v;
log(level) << "replSet load config couldn't get from " << h.toString() << ' ' << e.what() << rsLog;
return;
}
from(cfg);
checkRsConfig();
_ok = true;
log(level) << "replSet load config ok from " << (h.isSelf() ? "self" : h.toString()) << rsLog;
}