本文整理汇总了C++中QTcpServer::socketDescriptor方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpServer::socketDescriptor方法的具体用法?C++ QTcpServer::socketDescriptor怎么用?C++ QTcpServer::socketDescriptor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTcpServer
的用法示例。
在下文中一共展示了QTcpServer::socketDescriptor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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?
}
示例2: createListeningSocket
int ServerManager::createListeningSocket(const QHostAddress &address, quint16 port)
{
int sd = 0;
QTcpServer server;
if (!server.listen(address, port)) {
qCritical("listen failed");
return sd;
}
sd = ::fcntl(server.socketDescriptor(), F_DUPFD, 0);
#if defined(FD_CLOEXEC)
::fcntl(sd, F_SETFD, 0);
#endif
server.close();
return sd;
}
示例3: nativeListen
/*!
Listen a port for connections on a socket.
This function must be called in a tfmanager process.
*/
int TApplicationServerBase::nativeListen(const QHostAddress &address, quint16 port, OpenFlag flag)
{
int sd = 0;
QTcpServer server;
if (!server.listen(address, port)) {
tSystemError("Listen failed port:%d", port);
return sd;
}
sd = duplicateSocket(server.socketDescriptor()); // duplicate
if (flag == CloseOnExec) {
::fcntl(sd, F_SETFD, ::fcntl(sd, F_GETFD) | FD_CLOEXEC);
} else {
::fcntl(sd, F_SETFD, 0); // clear
}
::fcntl(sd, F_SETFL, ::fcntl(sd, F_GETFL) | O_NONBLOCK); // non-block
server.close();
return sd;
}