kdeconnect-kde/core/backends/lan/server.cpp

51 lines
1.2 KiB
C++
Raw Normal View History

2015-07-05 14:23:53 +01:00
/**
* SPDX-FileCopyrightText: 2015 Vineet Garg <grg.vineet@gmail.com>
2015-07-05 14:23:53 +01:00
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
2015-07-05 14:23:53 +01:00
*/
#include "server.h"
#include "kdeconnectconfig.h"
#include "lanlinkprovider.h"
#include <QSslError>
2015-07-05 14:23:53 +01:00
#include <QSslKey>
#include <QSslSocket>
Server::Server(QObject *parent)
: QTcpServer(parent)
2015-07-05 14:23:53 +01:00
{
2016-07-04 18:34:28 +01:00
connect(this, &QTcpServer::acceptError, this, &Server::errorFound);
2015-07-05 14:23:53 +01:00
}
void Server::incomingConnection(qintptr socketDescriptor)
{
QSslSocket *serverSocket = new QSslSocket(parent());
2015-07-05 14:23:53 +01:00
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
2020-04-06 01:38:19 +01:00
QObject::connect(this, &Server::closed, serverSocket, &QSslSocket::abort);
addPendingConnection(serverSocket);
2015-07-05 14:23:53 +01:00
} else {
qWarning() << "setSocketDescriptor failed" << serverSocket->errorString();
2015-07-05 14:23:53 +01:00
delete serverSocket;
}
}
QSslSocket *Server::nextPendingConnection()
{
return qobject_cast<QSslSocket *>(QTcpServer::nextPendingConnection());
2015-07-09 23:27:27 +01:00
}
2016-07-04 18:34:28 +01:00
void Server::errorFound(QAbstractSocket::SocketError socketError)
{
qDebug() << "error:" << socketError;
}
2020-04-06 01:38:19 +01:00
void Server::close()
{
QTcpServer::close();
Q_EMIT closed();
}
#include "moc_server.cpp"