Example #1
0
bool TcpFace::open(const Contact& address) {
    YARP_DEBUG(Logger::get(),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.addSocket("tcp",
                                          NameConfig::getHostName(),
                                          localAddr.get_port_number());
    }
#else
    int result = peerAcceptor.open(address);
    if (address.getPort()<=0) {
        this->address = address.addSocket("tcp",
                                          NameConfig::getHostName(),
                                          peerAcceptor.get_port_number());
    }
#endif
    if (result==-1) {
        return false;
    }

    return true;
}
Example #2
0
Contact Contact::fromString(const ConstString& txt) {
    ConstString str(txt);
    Contact c;
    ConstString::size_type start = 0;
    ConstString::size_type base = str.find("://");
    ConstString::size_type offset = 2;
    if (base==ConstString::npos) {
        base = str.find(":/");
        offset = 1;
    }
    if (base==ConstString::npos) {
        if (str.length()>0 && str[0] == '/') {
            base = 0;
            offset = 0;
        }
    }
    if (base!=ConstString::npos) {
        c = Contact::byCarrier(str.substr(0,base));
        start = base+offset;
        // check if we have a direct machine:NNN syntax
        ConstString::size_type colon = ConstString::npos;
        int mode = 0;
        int nums = 0;
        ConstString::size_type i;
        for (i=start+1; i<str.length(); i++) {
            char ch = str[i];
            if (ch==':') {
                if (mode == 0) {
                    colon = i;
                    mode = 1;
                    continue;
                } else {
                    mode = -1;
                    break;
                }
            }
            if (ch=='/') {
                break;
            }
            if (mode==1) {
                if (ch>='0'&&ch<='9') {
                    nums++;
                    continue;
                } else {
                    mode = -1;
                    break;
                }
            }
        }
        if (mode==1 && nums>=1) {
            // yes, machine:nnn
            ConstString machine = str.substr(start+1,colon-start-1);
            ConstString portnum = str.substr(colon+1, nums);
            c = c.addSocket(c.getCarrier()==""?"tcp":c.getCarrier().c_str(),
                            machine,
                            atoi(portnum.c_str()));
            start = i;
        }
    }
    ConstString rname = str.substr(start);
    if (rname!="/") {
        c = c.addName(rname.c_str());
    }
    return c;
}
Example #3
0
 QueueManager() : mutex(1) {
     attach(port);
     Contact c = Contact::byName("/help");
     c = c.addSocket("tcp","localhost",80);
     port.open(c);
 }