本文整理汇总了C++中QSslSocket::state方法的典型用法代码示例。如果您正苦于以下问题:C++ QSslSocket::state方法的具体用法?C++ QSslSocket::state怎么用?C++ QSslSocket::state使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSslSocket
的用法示例。
在下文中一共展示了QSslSocket::state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: serverDisconnectWithBuffered
// Test buffered socket being properly closed on remote disconnect
void tst_QAbstractSocket::serverDisconnectWithBuffered()
{
QTcpServer tcpServer;
#ifndef QT_NO_SSL
QSslSocket testSocket;
#else
QTcpSocket testSocket;
#endif
QVERIFY(tcpServer.listen(QHostAddress::LocalHost));
testSocket.connectToHost(tcpServer.serverAddress(), tcpServer.serverPort());
// Accept connection on server side
QVERIFY(tcpServer.waitForNewConnection(5000));
QTcpSocket *newConnection = tcpServer.nextPendingConnection();
// Send one char and drop link
QVERIFY(newConnection != NULL);
QVERIFY(newConnection->putChar(0));
QVERIFY(newConnection->flush());
delete newConnection;
QVERIFY(testSocket.waitForConnected(5000)); // ready for write
QVERIFY(testSocket.state() == QAbstractSocket::ConnectedState);
QSignalSpy spyStateChanged(&testSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)));
QSignalSpy spyDisconnected(&testSocket, SIGNAL(disconnected()));
QVERIFY(testSocket.waitForReadyRead(5000)); // have one char already in internal buffer
char buf[128];
QCOMPARE(testSocket.read(buf, sizeof(buf)), Q_INT64_C(1));
if (testSocket.state() != QAbstractSocket::UnconnectedState) {
QVERIFY(testSocket.waitForDisconnected(5000));
QVERIFY(testSocket.state() == QAbstractSocket::UnconnectedState);
}
// Test signal emitting
QVERIFY(spyDisconnected.count() == 1);
QVERIFY(spyStateChanged.count() > 0);
QVERIFY(qvariant_cast<QAbstractSocket::SocketState>(spyStateChanged.last().first())
== QAbstractSocket::UnconnectedState);
}