本文整理汇总了C++中BNetworkAddress::Port方法的典型用法代码示例。如果您正苦于以下问题:C++ BNetworkAddress::Port方法的具体用法?C++ BNetworkAddress::Port怎么用?C++ BNetworkAddress::Port使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BNetworkAddress
的用法示例。
在下文中一共展示了BNetworkAddress::Port方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memcmp
bool
BNetworkAddress::Equals(const BNetworkAddress& other, bool includePort) const
{
if (IsEmpty() && other.IsEmpty())
return true;
if (Family() != other.Family()
|| (includePort && Port() != other.Port())) {
return false;
}
switch (fAddress.ss_family) {
case AF_INET:
{
sockaddr_in& address = (sockaddr_in&)fAddress;
sockaddr_in& otherAddress = (sockaddr_in&)other.fAddress;
return memcmp(&address.sin_addr, &otherAddress.sin_addr,
sizeof(address.sin_addr)) == 0;
}
case AF_INET6:
{
sockaddr_in6& address = (sockaddr_in6&)fAddress;
sockaddr_in6& otherAddress = (sockaddr_in6&)other.fAddress;
return memcmp(&address.sin6_addr, &otherAddress.sin6_addr,
sizeof(address.sin6_addr)) == 0;
}
default:
if (fAddress.ss_len != other.fAddress.ss_len)
return false;
return memcmp(&fAddress, &other.fAddress, fAddress.ss_len);
}
}
示例2: _Setup
status_t
BProxySecureSocket::Connect(const BNetworkAddress& peer, bigtime_t timeout)
{
status_t status = InitCheck();
if (status != B_OK)
return status;
BSocket::Connect(fProxyAddress, timeout);
if (status != B_OK)
return status;
BString connectRequest;
connectRequest.SetToFormat("CONNECT %s:%d HTTP/1.0\r\n\r\n",
peer.HostName().String(), peer.Port());
BSocket::Write(connectRequest.String(), connectRequest.Length());
char buffer[256];
ssize_t length = BSocket::Read(buffer, sizeof(buffer) - 1);
if (length <= 0)
return length;
buffer[length] = '\0';
int httpStatus = 0;
int matches = scanf(buffer, "HTTP/1.0 %d %*[^\r\n]\r\n\r\n", httpStatus);
if (matches != 2)
return B_BAD_DATA;
if (httpStatus < 200 || httpStatus > 299)
return B_BAD_VALUE;
return _Setup();
}
示例3: Port
bool
BNetworkAddress::operator<(const BNetworkAddress& other) const
{
if (Family() < other.Family())
return true;
if (Family() > other.Family())
return false;
int compare;
switch (fAddress.ss_family) {
default:
case AF_INET:
{
sockaddr_in& address = (sockaddr_in&)fAddress;
sockaddr_in& otherAddress = (sockaddr_in&)other.fAddress;
compare = memcmp(&address.sin_addr, &otherAddress.sin_addr,
sizeof(address.sin_addr));
break;
}
case AF_INET6:
{
sockaddr_in6& address = (sockaddr_in6&)fAddress;
sockaddr_in6& otherAddress = (sockaddr_in6&)other.fAddress;
compare = memcmp(&address.sin6_addr, &otherAddress.sin6_addr,
sizeof(address.sin6_addr));
break;
}
case AF_LINK:
if (LinkLevelAddressLength() < other.LinkLevelAddressLength())
return true;
if (LinkLevelAddressLength() > other.LinkLevelAddressLength())
return true;
// TODO: could compare index, and name, too
compare = memcmp(LinkLevelAddress(), other.LinkLevelAddress(),
LinkLevelAddressLength());
break;
}
if (compare < 0)
return true;
if (compare > 0)
return false;
return Port() < other.Port();
}