当前位置: 首页>>代码示例>>C++>>正文


C++ HostAndPort::isSelf方法代码示例

本文整理汇总了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;
        }
    }
开发者ID:EshaMaharishi,项目名称:pubsub,代码行数:24,代码来源:pubsub_sendsock.cpp

示例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;
    }
开发者ID:CoolCloud,项目名称:mongo,代码行数:77,代码来源:rs_config.cpp


注:本文中的HostAndPort::isSelf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。