Files
o3de/Code/Tools/AssetProcessor/native/utilities/BatchApplicationServer.cpp
T
Steve Pham 38261d0800 Shorten copyright headers by splitting into 2 lines (#2213)
* Updated all copyright headers to split the longer original copyright line into 2 shorter lines

Signed-off-by: Steve Pham <spham@amazon.com>
2021-07-16 15:25:48 -07:00

63 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()
{
}
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, 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;
}