本文整理汇总了C++中IPAddress::getPort方法的典型用法代码示例。如果您正苦于以下问题:C++ IPAddress::getPort方法的具体用法?C++ IPAddress::getPort怎么用?C++ IPAddress::getPort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPAddress
的用法示例。
在下文中一共展示了IPAddress::getPort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setLocalAddress
void Connection::setLocalAddress(const IPAddress &addr) {
if (addr.getIP()) {
string ip(IPAddress(addr.getIP()).getHost());
evhttp_connection_set_local_address(con, ip.c_str());
}
if (addr.getPort()) evhttp_connection_set_local_port(con, addr.getPort());
}
示例2: connect
void SocketDefaultImpl::connect(const IPAddress &ip) {
if (!isOpen()) open();
LOG_INFO(3, "Connecting to " << ip);
try {
struct sockaddr_in sin;
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons((short)ip.getPort());
sin.sin_addr.s_addr = htonl(ip);
SysError::clear();
if (::connect((socket_t)socket, (struct sockaddr *)&sin, sizeof(sin)) == -1)
if (SysError::get() != EINPROGRESS)
THROWS("Failed to connect to " << ip << ": " << SysError());
connected = true;
capture(ip, false);
} catch (const Exception &e) {
close();
throw;
}
}
示例3: con
Connection::Connection(cb::Event::Base &base, DNSBase &dns, BufferEvent &bev,
const IPAddress &peer) :
con(evhttp_connection_base_bufferevent_new
(base.getBase(), dns.getDNSBase(), bev.adopt(), peer.getHost().c_str(),
peer.getPort())), deallocate(true) {
if (!con) THROWS("Failed to create connection to " << peer);
}
示例4: bind
void SocketDefaultImpl::bind(const IPAddress &ip) {
if (!isOpen()) open();
struct sockaddr_in addr;
memset((void *)&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(ip.getPort());
addr.sin_addr.s_addr = htonl((unsigned)ip ? (unsigned)ip : INADDR_ANY);
SysError::clear();
if (::bind((socket_t)socket, (struct sockaddr *)&addr, sizeof(addr)) ==
SOCKET_ERROR)
THROWS("Could not bind socket to " << ip << ": " << SysError());
}