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


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

本文整理汇总了C++中HostAndPort::port方法的典型用法代码示例。如果您正苦于以下问题:C++ HostAndPort::port方法的具体用法?C++ HostAndPort::port怎么用?C++ HostAndPort::port使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HostAndPort的用法示例。


在下文中一共展示了HostAndPort::port方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: isSelf

bool isSelf(const HostAndPort& hostAndPort, ServiceContext* const ctx) {
    // Fastpath: check if the host&port in question is bound to one
    // of the interfaces on this machine.
    // No need for ip match if the ports do not match
    if (hostAndPort.port() == serverGlobalParams.port) {
        std::vector<std::string> myAddrs = serverGlobalParams.bind_ips;

        // If any of the bound addresses is the default route (0.0.0.0 on IPv4) it means we are
        // listening on all network interfaces and need to check against any of them.
        if (myAddrs.empty() ||
            std::any_of(myAddrs.cbegin(), myAddrs.cend(), [](std::string const& addrStr) {
                return HostAndPort(addrStr, serverGlobalParams.port).isDefaultRoute();
            })) {
            myAddrs = getBoundAddrs(IPv6Enabled());
        }

        const std::vector<std::string> hostAddrs =
            getAddrsForHost(hostAndPort.host(), hostAndPort.port(), IPv6Enabled());

        for (std::vector<std::string>::const_iterator i = myAddrs.begin(); i != myAddrs.end();
             ++i) {
            for (std::vector<std::string>::const_iterator j = hostAddrs.begin();
                 j != hostAddrs.end();
                 ++j) {
                if (*i == *j) {
                    return true;
                }
            }
        }
    }

    ctx->waitForStartupComplete();

    try {
        DBClientConnection conn;
        conn.setSoTimeout(30);  // 30 second timeout

        // We need to avoid the isMaster call triggered by a normal connect, which would
        // cause a deadlock. 'isSelf' is called by the Replication Coordinator when validating
        // a replica set configuration document, but the 'isMaster' command requires a lock on the
        // replication coordinator to execute. As such we call we call 'connectSocketOnly', which
        // does not call 'isMaster'.
        if (!conn.connectSocketOnly(hostAndPort).isOK()) {
            return false;
        }

        if (auth::isInternalAuthSet() && !conn.authenticateInternalUser().isOK()) {
            return false;
        }
        BSONObj out;
        bool ok = conn.simpleCommand("admin", &out, "_isSelf");
        bool me = ok && out["id"].type() == jstOID && instanceId == out["id"].OID();

        return me;
    } catch (const std::exception& e) {
        warning() << "couldn't check isSelf (" << hostAndPort << ") " << e.what() << std::endl;
    }

    return false;
}
开发者ID:ShaneHarvey,项目名称:mongo,代码行数:60,代码来源:isself.cpp

示例2: initSharding

    void PubSubSendSocket::initSharding(const std::string configServers) {
        if (!pubsubEnabled)
            return;

        vector<string> configdbs;
        splitStringDelim(configServers, &configdbs, ',');

        // find config db we are using for pubsub
        HostAndPort maxConfigHP;
        maxConfigHP.setPort(0);

        for (vector<string>::iterator it = configdbs.begin(); it != configdbs.end(); it++) {
            HostAndPort configHP = HostAndPort(*it);
            if (configHP.port() > maxConfigHP.port())
                maxConfigHP = configHP;
        }

        HostAndPort configPullEndpoint = HostAndPort(maxConfigHP.host(), maxConfigHP.port() + 1234);

        try {
            dbEventSocket = new zmq::socket_t(zmqContext, ZMQ_PUSH);
            dbEventSocket->connect(("tcp://" + configPullEndpoint.toString()).c_str());
        }
        catch (zmq::error_t& e) {
            log() << "PubSub could not connect to config server. Turning off db events..."
                  << causedBy(e);
            publishDataEvents = false;
        }

    }
开发者ID:EshaMaharishi,项目名称:pubsub,代码行数:30,代码来源:pubsub_sendsock.cpp

示例3: isSelf

    bool isSelf(const HostAndPort& hostAndPort) {

        // Fastpath: check if the host&port in question is bound to one
        // of the interfaces on this machine.
        // No need for ip match if the ports do not match
        if (hostAndPort.port() == serverGlobalParams.port) {
            std::vector<std::string> myAddrs = serverGlobalParams.bind_ip.empty() ?
              getBoundAddrs(IPv6Enabled()) :
              std::vector<std::string>();

            if (!serverGlobalParams.bind_ip.empty()) {
                boost::split(myAddrs, serverGlobalParams.bind_ip, boost::is_any_of(", "));
            }

            const std::vector<std::string> hostAddrs = getAddrsForHost(hostAndPort.host(),
                                                                       hostAndPort.port(),
                                                                       IPv6Enabled());

            for (std::vector<std::string>::const_iterator i = myAddrs.begin();
                 i != myAddrs.end(); ++i) {
                for (std::vector<std::string>::const_iterator j = hostAddrs.begin();
                     j != hostAddrs.end(); ++j) {
                    if (*i == *j) {
                        return true;
                    }
                }
            }
        }

        if (!Listener::getTimeTracker()) {
            // this ensures we are actually running a server
            // this may return true later, so may want to retry
            return false;
        }

        try {
            DBClientConnection conn;
            std::string errmsg;
            if (!conn.connect(hostAndPort, errmsg)) {
                return false;
            }

            if (getGlobalAuthorizationManager()->isAuthEnabled() && isInternalAuthSet()) {
                if (!authenticateInternalUser(&conn)) {
                    return false;
                }
            }
            BSONObj out;
            bool ok = conn.simpleCommand("admin" , &out, "_isSelf");
            bool me = ok && out["id"].type() == jstOID && instanceId == out["id"].OID();

            return me;
        }
        catch (const std::exception& e) {
            warning() << "could't check isSelf (" << hostAndPort << ") " << e.what() << std::endl;
        }

        return false;
    }
开发者ID:ANTco,项目名称:mongo,代码行数:59,代码来源:isself.cpp

示例4: appendGeneric

static void appendGeneric(const HostAndPort& hp, const SinkFunc& write) {
    // wrap ipv6 addresses in []s for roundtrip-ability
    if (hp.host().find(':') != std::string::npos) {
        write("[");
        write(hp.host());
        write("]");
    } else {
        write(hp.host());
    }
    if (hp.host().find('/') == std::string::npos) {
        write(":");
        write(hp.port());
    }
}
开发者ID:mongodb,项目名称:mongo,代码行数:14,代码来源:hostandport.cpp

示例5: getSlave

    HostAndPort ReplicaSetMonitor::getSlave( const HostAndPort& prev ) {
        // make sure its valid 
        if ( prev.port() > 0 ) {
            scoped_lock lk( _lock );
            for ( unsigned i=0; i<_nodes.size(); i++ ) {
                if ( prev != _nodes[i].addr ) 
                    continue;

                if ( _nodes[i].ok ) 
                    return prev;
                break;
            }
        }
        
        return getSlave();
    }
开发者ID:cangove,项目名称:mongo,代码行数:16,代码来源:dbclient_rs.cpp

示例6: 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

示例7: host

 bool HostAndPort::operator==(const HostAndPort& r) const {
     return host() == r.host() && port() == r.port();
 }
开发者ID:DesignByOnyx,项目名称:mongo,代码行数:3,代码来源:hostandport.cpp

示例8: port

 bool HostAndPort::operator<(const HostAndPort& r) const {
     const int cmp = host().compare(r.host());
     if (cmp)
         return cmp < 0;
     return port() < r.port();
 }
开发者ID:DesignByOnyx,项目名称:mongo,代码行数:6,代码来源:hostandport.cpp

示例9: isSelf

bool isSelf(const HostAndPort& hostAndPort) {
    // Fastpath: check if the host&port in question is bound to one
    // of the interfaces on this machine.
    // No need for ip match if the ports do not match
    if (hostAndPort.port() == serverGlobalParams.port) {
        std::vector<std::string> myAddrs = serverGlobalParams.bind_ip.empty()
            ? getBoundAddrs(IPv6Enabled())
            : std::vector<std::string>();

        if (!serverGlobalParams.bind_ip.empty()) {
            boost::split(myAddrs, serverGlobalParams.bind_ip, boost::is_any_of(", "));
        }

        const std::vector<std::string> hostAddrs =
            getAddrsForHost(hostAndPort.host(), hostAndPort.port(), IPv6Enabled());

        for (std::vector<std::string>::const_iterator i = myAddrs.begin(); i != myAddrs.end();
             ++i) {
            for (std::vector<std::string>::const_iterator j = hostAddrs.begin();
                 j != hostAddrs.end();
                 ++j) {
                if (*i == *j) {
                    return true;
                }
            }
        }
    }

    // Ensure that the server is up and ready to accept incoming network requests.
    const Listener* listener = Listener::getTimeTracker();
    if (!listener) {
        return false;
    }
    listener->waitUntilListening();

    try {
        DBClientConnection conn;
        conn.setSoTimeout(30);  // 30 second timeout

        // We need to avoid the isMaster call triggered by a normal connect, which would
        // cause a deadlock. 'isSelf' is called by the Replication Coordinator when validating
        // a replica set configuration document, but the 'isMaster' command requires a lock on the
        // replication coordinator to execute. As such we call we call 'connectSocketOnly', which
        // does not call 'isMaster'.
        if (!conn.connectSocketOnly(hostAndPort).isOK()) {
            return false;
        }

        if (getGlobalAuthorizationManager()->isAuthEnabled() && isInternalAuthSet()) {
            if (!conn.authenticateInternalUser()) {
                return false;
            }
        }
        BSONObj out;
        bool ok = conn.simpleCommand("admin", &out, "_isSelf");
        bool me = ok && out["id"].type() == jstOID && instanceId == out["id"].OID();

        return me;
    } catch (const std::exception& e) {
        warning() << "couldn't check isSelf (" << hostAndPort << ") " << e.what() << std::endl;
    }

    return false;
}
开发者ID:stevelyall,项目名称:mongol-db,代码行数:64,代码来源:isself.cpp


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