本文整理汇总了C++中Contact::addSocket方法的典型用法代码示例。如果您正苦于以下问题:C++ Contact::addSocket方法的具体用法?C++ Contact::addSocket怎么用?C++ Contact::addSocket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contact
的用法示例。
在下文中一共展示了Contact::addSocket方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open
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;
}
示例2: fromString
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;
}
示例3: QueueManager
QueueManager() : mutex(1) {
attach(port);
Contact c = Contact::byName("/help");
c = c.addSocket("tcp","localhost",80);
port.open(c);
}