本文整理汇总了C++中Contact::getHost方法的典型用法代码示例。如果您正苦于以下问题:C++ Contact::getHost方法的具体用法?C++ Contact::getHost怎么用?C++ Contact::getHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contact
的用法示例。
在下文中一共展示了Contact::getHost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: apply
ConstString NameServer::apply(const ConstString& txt, const Contact& remote) {
ConstString result = "no command given";
mutex.wait();
SplitString ss(txt.c_str());
if (ss.size()>=2) {
ConstString key = ss.get(1);
//YARP_DEBUG(Logger::get(),ConstString("dispatching to ") + key);
ss.set(1,remote.getHost().c_str());
result = dispatcher.dispatch(this,key.c_str(),ss.size()-1,
(char **)(ss.get()+1));
if (result == "") {
Bottle b = ndispatcher.dispatch(this,key.c_str(),ss.size()-1,
(char **)(ss.get()+1));
result = b.toString().c_str();
if (result!="") {
result = result + "\n";
result = terminate(result);
}
}
//YARP_DEBUG(Logger::get(), ConstString("name server request -- ") + txt);
//YARP_DEBUG(Logger::get(), ConstString("name server result -- ") + result);
}
mutex.post();
return result;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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);
}
示例7: 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
}
示例8: act
yarp::os::Contact NameServiceOnTriples::query(const ConstString& port) {
Contact check = Contact::fromString(port);
if (check.getHost()!="") return check;
Bottle cmd,reply,event;
Contact remote;
TripleSource& mem = *db;
NameTripleState act(cmd,reply,event,remote,mem);
return query(port,act,"");
}
示例9: b
bool yarp::os::impl::HttpCarrier::sendHeader(ConnectionState& proto) {
ConstString target = "GET / HTTP/1.0\r\n";
ConstString path = proto.getRoute().getToName();
if (path.size()>=2) {
target = "GET " + path + " HTTP/1.0\r\n";
}
Contact host = proto.getRoute().getToContact();
if (host.getHost()!="") {
target += "Host: ";
target += host.getHost();
target += "\r\n";
}
target += "\r\n";
Bytes b((char*)target.c_str(),target.length());
proto.os().write(b);
return true;
}
示例10: DgramTwoWayStream
bool yarp::os::impl::McastCarrier::becomeMcast(ConnectionState& proto, bool sender) {
#ifndef YARP_HAS_ACE
return false;
#else
YARP_UNUSED(sender);
DgramTwoWayStream *stream = new DgramTwoWayStream();
yAssert(stream!=YARP_NULLPTR);
Contact remote = proto.getStreams().getRemoteAddress();
Contact local;
local = proto.getStreams().getLocalAddress();
bool test = true;
//(yarp::NameConfig::getEnv("YARP_MCAST_TEST")!="");
/*
if (test) {
printf(" MULTICAST is being extended; some temporary status messages added\n");
printf(" Local: %s\n", local.toString().c_str());
printf(" Remote: %s\n", remote.toString().c_str());
}
*/
proto.takeStreams(YARP_NULLPTR); // free up port from tcp
if (sender) {
/*
Multicast behavior seems a bit variable.
We assume here that if packages need to be broadcast
to targets via different network interfaces, that
we'll need to send independently on those two
interfaces. This may or may not always be the case,
the author doesn't know, so is being cautious.
*/
key = proto.getRoute().getFromName();
if (test) {
key += "/net=";
key += local.getHost();
}
YARP_DEBUG(Logger::get(),
ConstString("multicast key: ") + key);
addSender(key);
}
bool ok = true;
if (isElect()||!sender) {
if (test) {
ok = stream->join(mcastAddress,sender,local);
} else {
ok = stream->join(mcastAddress,sender);
}
}
if (!ok) {
delete stream;
return false;
}
proto.takeStreams(stream);
return true;
#endif
}
示例11: needsLookup
static bool needsLookup(const Contact& contact)
{
if (contact.getHost() != "") {
return false;
}
if (contact.getCarrier() == "topic") {
return false;
}
return true;
}
示例12: 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());
}
示例13: sendHeader
bool MjpegCarrier::sendHeader(ConnectionState& proto) {
Name n(proto.getRoute().getCarrierName() + "://test");
ConstString pathValue = n.getCarrierModifier("path");
ConstString target = "GET /?action=stream\n\n";
if (pathValue!="") {
target = "GET /";
target += pathValue;
}
target += " HTTP/1.1\n";
Contact host = proto.getRoute().getToContact();
if (host.getHost()!="") {
target += "Host: ";
target += host.getHost();
target += "\r\n";
}
target += "\n";
Bytes b((char*)target.c_str(),target.length());
proto.os().write(b);
return true;
}
示例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();
}
示例15: 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());
}