You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Code/Tools/AssetProcessor/native/utilities/BatchApplicationServer.cpp

64 lines
1.9 KiB
C++

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <native/utilities/BatchApplicationServer.h>
#include "native/utilities/assetUtils.h"
BatchApplicationServer::BatchApplicationServer(QObject* parent)
: ApplicationServer(parent)
{
}
BatchApplicationServer::~BatchApplicationServer()
{
close();
}
bool BatchApplicationServer::startListening(unsigned short port)
{
if (!isListening())
{
if (port == 0)
{
quint16 listeningPort = AssetUtilities::ReadListeningPortFromSettingsRegistry();
m_serverListeningPort = static_cast<int>(listeningPort);
// In batch mode, make sure we use a different port from the GUI
++m_serverListeningPort;
}
else
{
// override the port
m_serverListeningPort = port;
}
// Since we're starting up builders ourselves and informing them of the port chosen, we can scan for a free port
while (!listen(QHostAddress::Any, static_cast<quint16>(m_serverListeningPort)))
{
auto error = serverError();
if (error == QAbstractSocket::AddressInUseError)
{
++m_serverListeningPort;
}
else
{
AZ_Error(AssetProcessor::ConsoleChannel, false, "Failed to start Asset Processor server. Error: %s", errorString().toStdString().c_str());
return false;
}
}
AZ_TracePrintf(AssetProcessor::ConsoleChannel, "Listening Port: %d\n", m_serverListeningPort);
ApplicationServerBus::Handler::BusConnect();
AZ_TracePrintf(AssetProcessor::DebugChannel, "Asset Processor server listening on port %d\n", m_serverListeningPort);
}
return true;
}