本文整理汇总了C++中Host::port方法的典型用法代码示例。如果您正苦于以下问题:C++ Host::port方法的具体用法?C++ Host::port怎么用?C++ Host::port使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Host
的用法示例。
在下文中一共展示了Host::port方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeServerText
QString ServersComboBox::makeServerText(const Host &host)
{
QString name;
name = host.address();
if (host.isValid()) {
if (name.indexOf(':') >= 0) {
name = '[' + name + ']';
}
name += ':' + QString::number(host.port());
}
return name;
}
示例2: send
bool UdpSocket::send(const Host& host, const char* data, int size)
{
const uint32_t addr = host.address();
const uint16_t port = htons(host.port());
sockaddr_in& to = mPriv->to;
if (to.sin_addr.s_addr != addr || to.sin_port != port) {
if (to.sin_addr.s_addr)
close(mPriv->client);
to.sin_family = AF_INET;
to.sin_addr.s_addr = addr;
to.sin_port = port;
mPriv->client = socket(AF_INET, SOCK_DGRAM, 0);
if (mPriv->client == INVALID_SOCKET) {
memset(&to, 0, sizeof(sockaddr_in));
const int err = socketError();
fprintf(stderr, "socket failed in send: %d %s\n", err, socketErrorMessage(err).c_str());
return false;
}
}
int err;
ssize_t total = 0, sent;
do {
sent = sendto(mPriv->client, &data[total], size - total, 0, reinterpret_cast<sockaddr*>(&to), sizeof(sockaddr_in));
if (sent == SOCKET_ERROR) {
const int err = socketError();
if (err == EINTR)
continue;
fprintf(stderr, "sendto failed in send: %d %s (addr %u %u)\n", err, socketErrorMessage(err).c_str(), addr, host.port());
close(mPriv->client);
memset(&to, 0, sizeof(sockaddr_in));
return false;
}
total += sent;
} while (total < size);
assert(total == size);
return true;
}
示例3: data
QVariant HostModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_hosts.count())
return QVariant();
Host* host = m_hosts.at(index.row());
switch (index.column()) {
case 0: {
switch (role) {
case NameRole: return host->name();
case AddressRole: return host->address();
}
break;
}
case 1: if (role == Qt::DisplayRole) return host->name(); break;
case 2: if (role == Qt::DisplayRole) return host->productVersion(); break;
case 3: if (role == Qt::DisplayRole) return host->systemName(); break;
case 4: if (role == Qt::DisplayRole) return QString("%1:%2").arg(host->address()).arg(host->port()); break;
}
return QVariant();
}