本文整理汇总了C++中QSslSocket::localAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ QSslSocket::localAddress方法的具体用法?C++ QSslSocket::localAddress怎么用?C++ QSslSocket::localAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSslSocket
的用法示例。
在下文中一共展示了QSslSocket::localAddress方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool SignalProxy::IODevicePeer::isSecure() const {
#ifdef HAVE_SSL
QSslSocket *sslSocket = qobject_cast<QSslSocket *>(_device);
if(sslSocket)
return sslSocket->isEncrypted() || sslSocket->localAddress() == QHostAddress::LocalHost || sslSocket->localAddress() == QHostAddress::LocalHostIPv6;
#endif
QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(_device);
if(socket)
return socket->localAddress() == QHostAddress::LocalHost || socket->localAddress() == QHostAddress::LocalHostIPv6;
return false;
}
示例2: process
void SslServer::process(const PeerData &pd)
{
QByteArray data = pd.data;
if (data.isEmpty())
return;
quint8 command = getValue<quint8>(data.mid(0, 1));
data.remove(0, 1);
QSslSocket *socket = m_socket_hash[pd.descriptor];
if (!socket)
return;
switch (command)
{
case ServerCommand::PeerTryConnect:
{
if (data.size() != 20)
{
removeSocket(socket);
return;
}
QByteArray peer_id = data;
peer_id = cleanString(QLatin1String(peer_id)).toLatin1().leftJustified(peer_id.length(), char(0), true);
if (m_unavailable_list.contains(peer_id))
{
DEBUG_FUNCTION("IP:" << qPrintable(socket->peerAddress().toString()) << "User origin:" << qPrintable(m_id_hash.value(socket))
<< "User target:" << qPrintable(peer_id) << "Attempt to connect to unavailable user!");
writeWarning(socket, "You're trying to connect to a unavailable user!");
return;
}
if (peer_id == m_id_hash[socket])
{
DEBUG_FUNCTION("IP:" << qPrintable(socket->peerAddress().toString()) << "User origin:" << qPrintable(m_id_hash.value(socket))
<< "User target:" << qPrintable(peer_id) << "Attempt to connect to itself!");
writeWarning(socket, "You're trying to connect to itself!");
return;
}
if (!m_id_list.contains(peer_id))
{
DEBUG_FUNCTION("IP:" << qPrintable(socket->peerAddress().toString()) << "User origin:" << qPrintable(m_id_hash.value(socket))
<< "User target:" << qPrintable(peer_id) << "Attempt to connect to non connected user!");
writeWarning(socket, "You're trying to connect to a non connected user!");
return;
}
QSslSocket *target_socket = m_id_hash.key(peer_id);
if (m_connecting_connected_list.contains(target_socket))
{
DEBUG_FUNCTION("IP:" << qPrintable(socket->peerAddress().toString()) << "User origin:" << qPrintable(m_id_hash.value(socket))
<< "User target:" << qPrintable(peer_id) << "Attempt to connect to already connected user!");
writeWarning(socket, "User already connected!");
return;
}
m_connecting_connected_list.append(socket);
m_connecting_connected_list.append(target_socket);
QByteArray data;
data.append(getBytes<quint8>(ServerCommand::ConnectionRequested));
data.append(getBytes<quint32>(socket->localAddress().toIPv4Address()));
data.append(m_id_hash[socket]);
m_accept_hash.insert(target_socket, socket);
DEBUG_FUNCTION("IP:" << qPrintable(socket->peerAddress().toString()) << "User origin:" << qPrintable(m_id_hash.value(socket))
<< "User target:" << qPrintable(peer_id) << "Trying to connect to peer!");
target_socket->write(getBytes<qint32>(data.size()));
target_socket->write(data);
break;
}
case ServerCommand::ConnectionAnswer:
{
if (data.size() != 1)
{
removeSocket(socket);
return;
}
QSslSocket *socket_starter = m_accept_hash[socket];
bool accepted = getValue<bool>(data.mid(0, 1));
if (!socket_starter)
{
m_connecting_connected_list.removeAll(socket_starter);
m_connecting_connected_list.removeAll(socket);
if (accepted)
{
//.........这里部分代码省略.........