本文整理汇总了C++中Address::family方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::family方法的具体用法?C++ Address::family怎么用?C++ Address::family使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::family方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
std::string
to_string(const Address& a) {
std::stringstream ss;
if(a.family() == Address::IP4) {
char name[INET_ADDRSTRLEN];
::memset(&name, 0, INET_ADDRSTRLEN);
const sockaddr_in *v4 = reinterpret_cast<const sockaddr_in*>(&a.storage);
inet_ntop(Address::IP4, &v4->sin_addr, name, sizeof(in_addr));
ss << "ipv4(";
ss << name;
ss << ",";
ss << ntohs(v4->sin_port) ;
ss << ")";
} else if(a.family() == Address::IP6) {
char name[INET6_ADDRSTRLEN];
::memset(&name, 0, INET6_ADDRSTRLEN);
const sockaddr_in6 *v6 = reinterpret_cast<const sockaddr_in6*>(&a.storage);
inet_ntop(Address::IP6, &v6->sin6_addr, name, sizeof(in6_addr));
ss << "ipv6(";
ss << name;
ss << ",";
ss << ntohs(v6->sin6_port) ;
ss << ")";
}
return ss.str();
}
示例2: OpenSocket
int Interface::OpenSocket(const Address& io_addr)
{
// Create socket
int fd=socket(io_addr.family(),SOCK_STREAM,0);
if (fd != -1) {
// Set non-blocking
int status=fcntl(fd, F_GETFL, 0);
if (status!=-1 &&
fcntl(fd, F_SETFL, status|O_NONBLOCK)!=-1) {
// If an internet socket
if (io_addr.family()!=AF_UNIX) {
// disable Nagle algorithm
if (setsockopt(fd,IPPROTO_TCP,TCP_NODELAY,(void *)&status,
sizeof(int))==-1) {
logger->error("Failed to set no delay for socket");
}
}
} else {
logger->error("Failed to set socket non-blocking");
}
if (status==-1) {
close(fd);
fd=-1;
}
} else {
logger->error("Failed to open socket");
}
return fd;
}
示例3: connect
static void connect(uv_tcp_t* handle, const Address& address, void* data,
Callback cb) {
Connector* connector = new Connector(address, data, cb);
int rc = 0;
#if UV_VERSION_MAJOR == 0
if (address.family() == AF_INET) {
rc = uv_tcp_connect(&connector->req_, handle, *address.addr_in(),
on_connect);
} else {
rc = uv_tcp_connect6(&connector->req_, handle, *address.addr_in6(),
on_connect);
}
#else
rc = uv_tcp_connect(&connector->req_, handle, address.addr(),
on_connect);
#endif
if (rc != 0) {
connector->status_ = -1;
connector->cb_(connector);
delete connector;
}
}
示例4: compare
int Address::compare(const Address& a) const {
if (family() != a.family()) {
return family() < a.family() ? -1 : 1;
}
if (family() == AF_INET) {
if (addr_in()->sin_addr.s_addr != a.addr_in()->sin_addr.s_addr) {
return addr_in()->sin_addr.s_addr < a.addr_in()->sin_addr.s_addr ? -1 : 1;
}
} else if (family() == AF_INET6) {
return memcmp(&(addr_in6()->sin6_addr), &(a.addr_in6()->sin6_addr),
sizeof(addr_in6()->sin6_addr));
} else {
assert(false);
return -1;
}
return 0;
}
示例5: Acceptor
Acceptor(const Address& a)
: Handler(Socket(a.family(), Socket::TCP))
{
socket().bind(a);
socket().listen();
}
示例6: return
bool Address::operator < (const Address& addr) const
{
if (family() < addr.family()) return true;
return (port() < addr.port());
}
示例7: Open
int Interface::Open(const Address& io_addr)
{
if (io_addr.family()==AF_SERIAL)
OpenSerial(io_addr);
return OpenSocket(io_addr);
}