BatchApplicationServer.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/BatchApplicationServer.h>
  9. #include "native/utilities/assetUtils.h"
  10. BatchApplicationServer::BatchApplicationServer(QObject* parent)
  11. : ApplicationServer(parent)
  12. {
  13. }
  14. BatchApplicationServer::~BatchApplicationServer()
  15. {
  16. close();
  17. }
  18. bool BatchApplicationServer::startListening(unsigned short port)
  19. {
  20. if (!isListening())
  21. {
  22. if (port == 0)
  23. {
  24. quint16 listeningPort = AssetUtilities::ReadListeningPortFromSettingsRegistry();
  25. m_serverListeningPort = static_cast<int>(listeningPort);
  26. // In batch mode, make sure we use a different port from the GUI
  27. ++m_serverListeningPort;
  28. }
  29. else
  30. {
  31. // override the port
  32. m_serverListeningPort = port;
  33. }
  34. // Since we're starting up builders ourselves and informing them of the port chosen, we can scan for a free port
  35. while (!listen(QHostAddress::Any, static_cast<quint16>(m_serverListeningPort)))
  36. {
  37. auto error = serverError();
  38. if (error == QAbstractSocket::AddressInUseError)
  39. {
  40. ++m_serverListeningPort;
  41. }
  42. else
  43. {
  44. AZ_Error(AssetProcessor::ConsoleChannel, false, "Failed to start Asset Processor server. Error: %s", errorString().toStdString().c_str());
  45. return false;
  46. }
  47. }
  48. AZ_TracePrintf(AssetProcessor::ConsoleChannel, "Listening Port: %d\n", m_serverListeningPort);
  49. ApplicationServerBus::Handler::BusConnect();
  50. AZ_TracePrintf(AssetProcessor::DebugChannel, "Asset Processor server listening on port %d\n", m_serverListeningPort);
  51. }
  52. return true;
  53. }