本文整理汇总了C++中QTcpServer::hasPendingConnections方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpServer::hasPendingConnections方法的具体用法?C++ QTcpServer::hasPendingConnections怎么用?C++ QTcpServer::hasPendingConnections使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTcpServer
的用法示例。
在下文中一共展示了QTcpServer::hasPendingConnections方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defined
//----------------------------------------------------------------------------------
void tst_QTcpServer::ipv6Server()
{
#if defined(Q_OS_SYMBIAN)
QSKIP("Symbian: IPv6 is not yet supported", SkipAll);
#endif
//### need to enter the event loop for the server to get the connection ?? ( windows)
QTcpServer server;
if (!server.listen(QHostAddress::LocalHostIPv6, 8944)) {
QVERIFY(server.serverError() == QAbstractSocket::UnsupportedSocketOperationError);
return;
}
QVERIFY(server.serverPort() == 8944);
QVERIFY(server.serverAddress() == QHostAddress::LocalHostIPv6);
QTcpSocket client;
client.connectToHost("::1", 8944);
QVERIFY(client.waitForConnected(5000));
QVERIFY(server.waitForNewConnection());
QVERIFY(server.hasPendingConnections());
QTcpSocket *serverSocket = 0;
QVERIFY((serverSocket = server.nextPendingConnection()));
}
示例2: ServerSession
void SessionServer::Private::onNewTcpConnection() {
QTcpServer * server = dynamic_cast< QTcpServer * >( this->sender() );
assert( server || !"QTcpServer casting failed" );
while( server->hasPendingConnections() ) {
QTcpSocket * socket = server->nextPendingConnection();
ServerSession * session = new ServerSession( socket, this );
this->pendingSessions.push( session );
}
emit this->newConnection();
}
示例3: clientServerLoop
//----------------------------------------------------------------------------------
void tst_QTcpServer::clientServerLoop()
{
QTcpServer server;
QSignalSpy spy(&server, SIGNAL(newConnection()));
QVERIFY(!server.isListening());
QVERIFY(!server.hasPendingConnections());
QVERIFY(server.listen(QHostAddress::Any, 11423));
QVERIFY(server.isListening());
QTcpSocket client;
QHostAddress serverAddress = QHostAddress::LocalHost;
if (!(server.serverAddress() == QHostAddress::Any))
serverAddress = server.serverAddress();
client.connectToHost(serverAddress, server.serverPort());
QVERIFY(client.waitForConnected(5000));
QVERIFY(server.waitForNewConnection(5000));
QVERIFY(server.hasPendingConnections());
QCOMPARE(spy.count(), 1);
QTcpSocket *serverSocket = server.nextPendingConnection();
QVERIFY(serverSocket != 0);
QVERIFY(serverSocket->write("Greetings, client!\n", 19) == 19);
serverSocket->flush();
QVERIFY(client.waitForReadyRead(5000));
QByteArray arr = client.readAll();
QCOMPARE(arr.constData(), "Greetings, client!\n");
QVERIFY(client.write("Well, hello to you!\n", 20) == 20);
client.flush();
QVERIFY(serverSocket->waitForReadyRead(5000));
arr = serverSocket->readAll();
QCOMPARE(arr.constData(), "Well, hello to you!\n");
}
示例4: maxPendingConnections
//----------------------------------------------------------------------------------
void tst_QTcpServer::maxPendingConnections()
{
QFETCH_GLOBAL(bool, setProxy);
if (setProxy) {
QFETCH_GLOBAL(int, proxyType);
if (proxyType == QNetworkProxy::Socks5Proxy) {
QSKIP("With socks5 only 1 connection is allowed ever", SkipAll);
}
}
//### sees to fail sometimes ... a timing issue with the test on windows
QTcpServer server;
server.setMaxPendingConnections(2);
QTcpSocket socket1;
QTcpSocket socket2;
QTcpSocket socket3;
QVERIFY(server.listen());
socket1.connectToHost(QHostAddress::LocalHost, server.serverPort());
socket2.connectToHost(QHostAddress::LocalHost, server.serverPort());
socket3.connectToHost(QHostAddress::LocalHost, server.serverPort());
QVERIFY(server.waitForNewConnection(5000));
QVERIFY(server.hasPendingConnections());
QVERIFY(server.nextPendingConnection());
QVERIFY(server.hasPendingConnections());
QVERIFY(server.nextPendingConnection());
QVERIFY(!server.hasPendingConnections());
QCOMPARE(server.nextPendingConnection(), (QTcpSocket*)0);
QVERIFY(server.waitForNewConnection(5000));
QVERIFY(server.hasPendingConnections());
QVERIFY(server.nextPendingConnection());
}
示例5: constructing
void tst_QTcpServer::constructing()
{
QTcpServer socket;
// Check the initial state of the QTcpSocket.
QCOMPARE(socket.isListening(), false);
QCOMPARE((int)socket.serverPort(), 0);
QCOMPARE(socket.serverAddress(), QHostAddress());
QCOMPARE(socket.maxPendingConnections(), 30);
QCOMPARE(socket.hasPendingConnections(), false);
QCOMPARE(socket.socketDescriptor(), -1);
QCOMPARE(socket.serverError(), QAbstractSocket::UnknownSocketError);
// Check the state of the socket layer?
}
示例6: serverOK
void NetworkDialog::serverOK()
{
QTcpServer* server = qobject_cast<QTcpServer*>(sender());
Q_ASSERT(server);
m_socket = server->nextPendingConnection();
Q_ASSERT(m_socket);
// refuse all other connections
while (server->hasPendingConnections()) {
delete server->nextPendingConnection();
}
// reparent socket, so that we can safely destroy the server
m_socket->setParent(this);
delete server;
// we're done
accept();
}
示例7: bogusFds
void tst_QSocketNotifier::bogusFds()
{
#ifndef Q_OS_SYMBIAN
//behaviour of QSocketNotifier with an invalid fd is totally different across OS
//main point of this test was to check symbian backend doesn't crash
QSKIP("test only for symbian", SkipAll);
#else
QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Internal error");
QSocketNotifier max(std::numeric_limits<int>::max(), QSocketNotifier::Read);
QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Invalid socket specified");
QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Internal error");
QSocketNotifier min(std::numeric_limits<int>::min(), QSocketNotifier::Write);
QTest::ignoreMessage(QtWarningMsg, "QSocketNotifier: Internal error");
//bogus magic number is the first pseudo socket descriptor from symbian socket engine.
QSocketNotifier bogus(0x40000000, QSocketNotifier::Exception);
QSocketNotifier largestlegal(FD_SETSIZE - 1, QSocketNotifier::Read);
QSignalSpy maxspy(&max, SIGNAL(activated(int)));
QSignalSpy minspy(&min, SIGNAL(activated(int)));
QSignalSpy bogspy(&bogus, SIGNAL(activated(int)));
QSignalSpy llspy(&largestlegal, SIGNAL(activated(int)));
//generate some unrelated socket activity
QTcpServer server;
QVERIFY(server.listen(QHostAddress::LocalHost));
connect(&server, SIGNAL(newConnection()), &QTestEventLoop::instance(), SLOT(exitLoop()));
QTcpSocket client;
client.connectToHost(QHostAddress::LocalHost, server.serverPort());
QTestEventLoop::instance().enterLoop(5);
QVERIFY(server.hasPendingConnections());
//check no activity on bogus notifiers
QCOMPARE(maxspy.count(), 0);
QCOMPARE(minspy.count(), 0);
QCOMPARE(bogspy.count(), 0);
QCOMPARE(llspy.count(), 0);
#endif
}