ApplicationServer.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "native/utilities/ApplicationServer.h"
  9. #include <QTcpSocket>
  10. const char ApplicationServer::RandomListeningPortOption[] = "randomListeningPort";
  11. ApplicationServer::ApplicationServer(QObject* parent)
  12. : QTcpServer(parent)
  13. {
  14. }
  15. ApplicationServer::~ApplicationServer()
  16. {
  17. ApplicationServerBus::Handler::BusDisconnect();
  18. }
  19. void ApplicationServer::incomingConnection(qintptr socketDescriptor)
  20. {
  21. if (m_isShuttingDown)
  22. {
  23. // deny the connection and return.
  24. QTcpSocket sock;
  25. sock.setSocketDescriptor(socketDescriptor, QAbstractSocket::ConnectedState, QIODevice::ReadWrite);
  26. sock.close();
  27. return;
  28. }
  29. Q_EMIT newIncomingConnection(socketDescriptor);
  30. }
  31. int ApplicationServer::GetServerListeningPort() const
  32. {
  33. return m_serverListeningPort;
  34. }
  35. void ApplicationServer::QuitRequested()
  36. {
  37. // stop accepting messages and close the connection immediately.
  38. pauseAccepting();
  39. close();
  40. Q_EMIT ReadyToQuit(this);
  41. }