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


C++ Contact::getPort方法代码示例

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


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

示例1: unregisterName

Contact NameServer::unregisterName(const ConstString& name) {
    Contact prev = queryName(name);
    if (prev.isValid()) {
        if (prev.getPort()!=-1) {
            NameRecord& rec = getNameRecord(prev.getRegName());
            if (rec.isReusablePort()) {
                HostRecord& host = getHostRecord(prev.getHost());
                host.release(prev.getPort());
            }
            if (rec.isReusableIp()) {
                if (rec.getAddress().getCarrier()=="mcast") {
                    mcastRecord.releaseAddress(rec.getAddress().getHost().c_str());
                }
            }
            rec.clear();
            tmpNames.release(name);

            Bottle event;
            event.addVocab(Vocab::encode("del"));
            event.addString(name.c_str());
            onEvent(event);
        }
    }

    return queryName(name);
}
开发者ID:apaikan,项目名称:yarp,代码行数:26,代码来源:NameServer.cpp

示例2: open

bool TcpFace::open(const Contact& address) {
    YARP_DEBUG(Logger::get(), std::string("opening for address ") + address.toURI());

    this->address = address;
#ifdef YARP_HAS_ACE
    ACE_INET_Addr serverAddr((address.getPort()>0)?address.getPort():0);
    int result = peerAcceptor.open(serverAddr, 1);
    if (address.getPort()<=0) {
        ACE_INET_Addr localAddr;
        peerAcceptor.get_local_addr(localAddr);
        this->address = address;
        this->address.setSocket("tcp",
                                NameConfig::getHostName(),
                                localAddr.get_port_number());
    }
#else
    int result = peerAcceptor.open(address);
    if (address.getPort()<=0) {
        this->address = address;
        this->address.setSocket("tcp",
                                NameConfig::getHostName(),
                                peerAcceptor.get_port_number());
    }
#endif
    if (result==-1) {
        return false;
    }

    return true;
}
开发者ID:robotology,项目名称:yarp,代码行数:30,代码来源:TcpFace.cpp

示例3: restrictMcast

int DgramTwoWayStream::restrictMcast(ACE_SOCK_Dgram_Mcast * dmcast,
                                     const Contact& group,
                                     const Contact& ipLocal,
                                     bool add) {
    restrictInterfaceIp = ipLocal;

    YARP_INFO(Logger::get(),
              String("multicast connection ") + group.getHost() + " on network interface for " + ipLocal.getHost());
    int result = -1;
    // There's some major damage in ACE mcast interfaces.
    // Most require interface names, yet provide no way to query
    // these names - and in the end, convert to IP addresses.
    // Here we try to do an end run around ACE.

    // based on: ACE_SOCK_Dgram::set_nic

    ip_mreq multicast_address;
    ACE_INET_Addr group_addr(group.getPort(),
                             group.getHost().c_str());
    ACE_INET_Addr interface_addr(ipLocal.getPort(),
                                 ipLocal.getHost().c_str());
    multicast_address.imr_interface.s_addr =
        htonl (interface_addr.get_ip_address ());
    multicast_address.imr_multiaddr.s_addr =
        htonl (group_addr.get_ip_address ());

    if (add) {
        YARP_DEBUG(Logger::get(),"Trying to correct mcast membership...\n");
        result =
            ((ACE_SOCK*)dmcast)->set_option (IPPROTO_IP,
                                             IP_ADD_MEMBERSHIP,
                                             &multicast_address,
                                             sizeof (struct ip_mreq));
    } else {
        YARP_DEBUG(Logger::get(),"Trying to correct mcast output...");
        result =
            ((ACE_SOCK*)dmcast)->set_option (IPPROTO_IP,
                                             IP_MULTICAST_IF,
                                             &multicast_address.imr_interface.s_addr,
                                             sizeof (struct in_addr));

    }
    if (result!=0) {
        int num = errno;
        YARP_DEBUG(Logger::get(),
                   String("mcast result: ") +
                   strerror(num));
        if (num==98) {
            // our membership is already correct / Address already in use
            result = 0;
        }
        result = 0; // in fact, best to proceed for Windows.
    }

    return result;
}
开发者ID:Karma-Revolution,项目名称:yarp,代码行数:56,代码来源:DgramTwoWayStream.cpp

示例4: open

int SocketTwoWayStream::open(const Contact& address) {
    if (address.getPort()==-1) {
        return -1;
    }
    std::string host = address.getHost();
    yarp::os::impl::TcpConnector connector;
#ifdef YARP_HAS_ACE
    if (address.getHost() == "localhost") {
        // ACE does not like localhost.  At all.
        NameConfig config;
        host = config.getHostName(true);
    }
    ACE_INET_Addr addr(address.getPort(), host.c_str());
    YARP_timeval openTimeout;
    YARP_timeval *timeout = nullptr;
    if (address.hasTimeout()) {
        openTimeout.set(address.getTimeout());
        timeout = &openTimeout;
    }
    int result = connector.connect(stream, addr, timeout, ACE_Addr::sap_any, 1);
#else
    int result;

    if (address.hasTimeout())
    {
        YARP_timeval timeout;
        /* set timeout seconds and microseconds */
        timeout.tv_sec = (int) address.getTimeout();
        timeout.tv_usec = (address.getTimeout() - (int) address.getTimeout()) * 1000000;
        result = connector.connect(stream, address, &timeout);
    }
    else
    {
        result = connector.connect(stream, address, nullptr);
    }


#endif
    if (result>=0) {
        happy = true;
    } else {
        YARP_SPRINTF2(Logger::get(),
                      debug,
                      "TCP connection to tcp://%s:%d failed to open",
                      host.c_str(),
                      address.getPort());
    }
    updateAddresses();
    return result;
}
开发者ID:ale-git,项目名称:yarp,代码行数:50,代码来源:SocketTwoWayStream.cpp

示例5: registerName

Contact MultiNameSpace::registerName(const ConstString& name) {
    SpaceList lst = HELPER(this).getAll();
    Contact result;
    for (int i=0; i<(int)lst.size(); i++) {
        Contact iresult;
        if (result.getPort()<=0) {
            iresult = lst[i]->registerName(name);
        } else {
            iresult = lst[i]->registerContact(result);
        }
        if (i==0 || result.getPort()<=0) {
            result = iresult;
        }
    }
    return result;
}
开发者ID:JoErNanO,项目名称:yarp,代码行数:16,代码来源:MultiNameSpace.cpp

示例6: open

int ShmemHybridStream::open(const Contact& yarp_address,bool sender)
{
    m_bLinked=false;

    ACE_INET_Addr ace_address(yarp_address.getPort(),yarp_address.getHost().c_str());

    if (sender)
    {
        return connect(ace_address);
    }
    else
    {
        ACE_INET_Addr ace_server_addr(ace_address.get_port_number());

        int result = m_Acceptor.open(ace_server_addr);

        if (result<0)
        {
            YARP_ERROR(Logger::get(),ConstString("ShmemHybridStream open result")+NetType::toString(result));
            return result;
        }

        m_Acceptor.get_local_addr(ace_server_addr);

        m_LocalAddress = Contact(ace_server_addr.get_host_addr(),ace_server_addr.get_port_number());
        m_RemoteAddress = m_LocalAddress; // finalized in call to accept()

        return result;
    }

    return 1;
}
开发者ID:giuliavezzani,项目名称:yarp,代码行数:32,代码来源:ShmemHybridStream.cpp

示例7: yarp_symlink

int yarp_symlink(const char *to, const char *from) {
    //TODO: actually, it only works with ln -s /read rd, and yet it throwns
    //  some errors

    //YPath ypath(from);
    //if (!ypath.isStem()) { //Check that the path exists? Is it right?
    //    return -ENOENT;
    //}

    //Create the new Contact
    //Contact src = Network::queryName(from);
    //printf("source [%s] is %s\n", from, src.toString().c_str());
    //Contact dest = Contact::byName(to).addSocket(src.getCarrier(),src.getHost(),src.getPort());
    //printf("dest [%s] should be %s\n", to, src.toString().c_str());
    //Network::registerContact(dest);

    printf("SYMLINK requested from [%s] to [%s]\n", from, to);

    // special symlink entry
    //Contact src = Network::queryName(to);
    Contact dest = Contact::byName(from).addSocket("symlink",
                                                   "none",
                                                   1);
    printf("Planning to register %s / %d / %d\n", 
           dest.toString().c_str(),
           dest.isValid(),
           dest.getPort());
    Network::registerContact(dest);
    Network::setProperty(from,"link",Value(to));

    return 0;
}
开发者ID:JoErNanO,项目名称:yarp,代码行数:32,代码来源:link.cpp

示例8: botify

Bottle NameServer::botify(const Contact& address) {
    Bottle result;
    if (address.isValid()) {
        Bottle bname;
        bname.addString("name");
        bname.addString(address.getRegName().c_str());
        Bottle bip;
        bip.addString("ip");
        bip.addString(address.getHost().c_str());
        Bottle bnum;
        bnum.addString("port_number");
        bnum.addInt(address.getPort());
        Bottle bcarrier;
        bcarrier.addString("carrier");
        bcarrier.addString(address.getCarrier().c_str());

        result.addString("port");
        result.addList() = bname;
        result.addList() = bip;
        result.addList() = bnum;
        result.addList() = bcarrier;
    } else {
        Bottle bstate;
        bstate.addString("error");
        bstate.addInt(-2);
        bstate.addString("port not known");
        result.addString("port");
        result.addList() = bstate;
    }
    return result;
}
开发者ID:apaikan,项目名称:yarp,代码行数:31,代码来源:NameServer.cpp

示例9: join

bool DgramTwoWayStream::join(const Contact& group, bool sender,
                             const Contact& ipLocal) {
#ifdef YARP_HAS_ACE
    YARP_DEBUG(Logger::get(),String("subscribing to mcast address ") +
               group.toURI() + " for " +
               (sender?"writing":"reading"));

    multiMode = true;

    if (sender) {
        if (ipLocal.isValid()) {
            return openMcast(group,ipLocal);
        } else {
            // just use udp as normal
            return open(group);
        }
        //return;
    }

    ACE_SOCK_Dgram_Mcast *dmcast = new ACE_SOCK_Dgram_Mcast;

    //possible flags: ((ACE_SOCK_Dgram_Mcast::options)(ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL | ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES));

    dgram = dmcast;
    mgram = dmcast;
    yAssert(dgram!=NULL);

    ACE_INET_Addr addr(group.getPort(),group.getHost().c_str());

    int result = -1;
    if (ipLocal.isValid()) {
        result = 0;
        result = dmcast->join(addr,1);

        if (result==0) {
            result = restrictMcast(dmcast,group,ipLocal,true);
        }
    } else {
        result = dmcast->join(addr,1);
    }

    configureSystemBuffers();

    if (result!=0) {
        YARP_ERROR(Logger::get(),"cannot connect to multi-cast address");
        happy = false;
        return false;
    }
    localAddress = group;
    remoteAddress = group;
    localHandle.set(localAddress.getPort(),localAddress.getHost().c_str());
    remoteHandle.set(remoteAddress.getPort(),remoteAddress.getHost().c_str());

    allocate();
    return true;
#else
    return false;
#endif
}
开发者ID:Karma-Revolution,项目名称:yarp,代码行数:59,代码来源:DgramTwoWayStream.cpp

示例10: shared_open

/**
 * Open the server port and listen for clients
 */
int TcpAcceptor::shared_open(const Contact& address) {

    struct sockaddr_in servAddr;
    servAddr.sin_addr.s_addr = INADDR_ANY;
    servAddr.sin_family = AF_INET;
    servAddr.sin_port = htons((address.getPort()>0)?address.getPort():0);
    inet_aton(address.getHost().c_str(), &servAddr.sin_addr);
    memset(servAddr.sin_zero, '\0', sizeof servAddr.sin_zero);

//    servAddress = Address(inet_ntoa(servAddr.sin_addr),servAddr.sin_port);

    if (bind(get_handle(), (struct sockaddr *)&servAddr,
            sizeof (struct sockaddr)) == -1) {
        perror("At bind(sockfd) there was an error...");
        return -1;
    }

    if (listen(get_handle(), BACKLOG) == -1) {
        perror("At listen(sockfd) there was an error...");
        return -1;
    }

    struct sigaction sa;
    sa.sa_handler = sigchld_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    if (sigaction(SIGCHLD, &sa, NULL) == -1) {
        perror("At sigaction(address) there was an error...");
        return -1;
    }

    struct sockaddr_in sin;
    socklen_t addrlen = sizeof(sin);
    if (getsockname(get_handle(), (struct sockaddr *)&sin, &addrlen) == 0 &&
	sin.sin_family == AF_INET &&
	addrlen == sizeof(sin)) {
      port_number = (int)ntohs(sin.sin_port);
    } else {
      perror("At getsockname(address) there was an error...");
      return -1;
    }

    return 1;
}
开发者ID:JoErNanO,项目名称:yarp,代码行数:47,代码来源:TcpAcceptor.cpp

示例11: rosify

Contact RosNameSpace::rosify(const Contact& contact) {
    ConstString carrier = ((contact.getCarrier() == "rosrpc")  ? "rosrpc" : "http");
    ConstString hostname = contact.getHost();
    if (yarp::os::impl::NameConfig::isLocalName(hostname)) {
        char hn[HOST_NAME_MAX];
        yarp::os::gethostname(hn, sizeof(hn));
        hostname = hn;
    }
    return Contact(carrier, hostname, contact.getPort());
}
开发者ID:jgvictores,项目名称:yarp,代码行数:10,代码来源:RosNameSpace.cpp

示例12: textify

ConstString NameServer::textify(const Contact& address) {
    ConstString result = "";
    if (address.isValid()) {
        if (address.getPort()>=0) {
            result = "registration name ";
            result = result + address.getRegName() +
                " ip " + address.getHost() + " port " +
                NetType::toString(address.getPort()) + " type " +
                address.getCarrier() + "\n";
        } else {
            result = "registration name ";
            result = result + address.getRegName() +
                " ip " + "none" + " port " +
                "none" + " type " +
                address.getCarrier() + "\n";
        }
    }
    return result;
}
开发者ID:apaikan,项目名称:yarp,代码行数:19,代码来源:NameServer.cpp

示例13: appendEntry

 void appendEntry(yarp::os::Bottle& reply, const Contact& c) {
   Bottle& info = reply.addList();
   info.addString("registration");
   info.addString("name");
   info.addString(c.getName().c_str());
   info.addString("ip");
   info.addString(c.getHost().c_str());
   info.addString("port");
   info.addInt(c.getPort());
   info.addString("type");
   info.addString(c.getCarrier().c_str());
 }
开发者ID:jgvictores,项目名称:yarp,代码行数:12,代码来源:main.cpp

示例14: requestTopic

 void requestTopic(NodeArgs& na) {
     ConstString topic = na.args.get(0).asString();
     Contact c = lookup(topic);
     if (!c.isValid()) {
         na.fail("Cannot find topic");
         return;
     }
     na.reply.addString("TCPROS");
     na.reply.addString(c.getHost());
     na.reply.addInt(c.getPort());
     na.success();
 }
开发者ID:andreadelprete,项目名称:yarp,代码行数:12,代码来源:Node.cpp

示例15: queryName

Contact NetworkBase::queryName(const ConstString& name) {
    YARP_SPRINTF1(Logger::get(),debug,"query name %s",name.c_str());
    if (getNameServerName()==name) {
        YARP_SPRINTF1(Logger::get(),debug,"query recognized as name server: %s",name.c_str());
        return getNameServerContact();
    }
    Contact c = c.fromString(name);
    if (c.isValid()&&c.getPort()>0) {
        return c;
    }
    return getNameSpace().queryName(name);
}
开发者ID:giuliavezzani,项目名称:yarp,代码行数:12,代码来源:Network.cpp


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