void checkTimeoutNetworkExists() { ContactStyle style; style.timeout = 2.0; report(0,"checking Network::exists timeout"); Port p; p.open("/tcp"); Contact c = p.where(); bool ok = Network::exists("/tcp",style); checkTrue(ok,"a yarp port"); p.close(); TcpFace face; Contact address(c.getHost(),c.getPort()); checkTrue(face.open(address),"open server socket, timeout check proceeds"); Network::registerContact(c); ok = Network::exists("/tcp",style); Network::unregisterContact(c); checkFalse(ok,"not a yarp port"); face.close(); }
String NameClient::send(const String& cmd, bool multi) { //printf("*** OLD YARP command %s\n", cmd.c_str()); setup(); if (NetworkBase::getQueryBypass()) { ContactStyle style; Bottle bcmd(cmd.c_str()), reply; NetworkBase::writeToNameServer(bcmd,reply,style); ConstString si = reply.toString(), so; for (int i=0; i<(int)si.length(); i++) { if (si[i]!='\"') { so += si[i]; } } return so.c_str(); } bool retried = false; bool retry = false; String result; Contact server = getAddress(); float timeout = 10; server.setTimeout(timeout); do { YARP_DEBUG(Logger::get(),String("sending to nameserver: ") + cmd); if (isFakeMode()) { //YARP_DEBUG(Logger::get(),"fake mode nameserver"); return getServer().apply(cmd,Contact::bySocket("tcp","127.0.0.1",NetworkBase::getDefaultPortRange())) + "\n"; } TcpFace face; YARP_DEBUG(Logger::get(),String("connecting to ") + getAddress().toURI()); OutputProtocol *ip = NULL; if (!retry) { ip = face.write(server); } else { retried = true; } if (ip==NULL) { YARP_INFO(Logger::get(),"No connection to nameserver"); if (!allowScan) { YARP_INFO(Logger::get(),"*** try running: yarp detect ***"); } Contact alt; if (!isFakeMode()) { if (allowScan) { YARP_INFO(Logger::get(),"no connection to nameserver, scanning mcast"); reportScan = true; #ifdef YARP_HAS_ACE alt = FallbackNameClient::seek(); #else return ""; // nothing to do, nowhere to turn #endif } } if (alt.isValid()) { address = alt; if (allowSaveScan) { reportSaveScan = true; NameConfig nc; nc.setAddress(alt); nc.toFile(); } server = getAddress(); server.setTimeout(timeout); ip = face.write(server); if (ip==NULL) { YARP_ERROR(Logger::get(), "no connection to nameserver, scanning mcast"); return ""; } } else { return ""; } } String cmdn = cmd + "\n"; Bytes b((char*)cmdn.c_str(),cmdn.length()); ip->getOutputStream().write(b); bool more = multi; while (more) { String line = ""; line = ip->getInputStream().readLine(); if (!(ip->isOk())) { more = false; //YARP_DEBUG(Logger::get(), e.toString() + " <<< exception from name server"); retry = true; break; } if (line.length()>1) { if (line[0] == '*'||line[0] == '[') { more = false; } } result += line + "\n"; } ip->close(); delete ip; YARP_SPRINTF1(Logger::get(), debug, "<<< received from nameserver: %s",result.c_str()); } while (retry&&!retried); return result; }
OutputProtocol *Carriers::connect(const Contact& address) { TcpFace tcpFace; return tcpFace.write(address); }