Clang/Clazy pass over AzCore (#5045)
* Multiple cleanups ( tidy etc. ) Coalesce nested namespaces. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Multiple cleanups ( tidy etc. ) cntd. Converted Uuid into POD ( defaulted the constructor ) Add `&/const &` to `for` loops that benefit from their use Some Qt optimizations ( string ref, prevent container detaches, etc. ) Replace `::bind` in a few places. Replaced the use of AZ_CRC with AZ_CRC_CE in a few places. Replace a few `typedef`s with `using`s Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Linux compilation fix. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Apply review suggestions. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Fix vs2019 build Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Small clang re-format in StringFunc.cpp Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com> * Apply reviewer's suggestions. Signed-off-by: nemerle <96597+nemerle@users.noreply.github.com>
This commit is contained in:
@@ -13,73 +13,67 @@
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace AZ
|
||||
namespace AZ::Debug::Platform
|
||||
{
|
||||
namespace Debug
|
||||
{
|
||||
namespace Platform
|
||||
{
|
||||
#if defined(AZ_ENABLE_DEBUG_TOOLS)
|
||||
bool performDebuggerDetection()
|
||||
bool performDebuggerDetection()
|
||||
{
|
||||
AZ::IO::SystemFile processStatusFile;
|
||||
if (!processStatusFile.Open("/proc/self/status", AZ::IO::SystemFile::SF_OPEN_READ_ONLY))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
char buffer[4096];
|
||||
AZ::IO::SystemFile::SizeType numRead = processStatusFile.Read(sizeof(buffer), buffer);
|
||||
|
||||
const AZStd::string_view processStatusView(buffer, buffer + numRead);
|
||||
constexpr AZStd::string_view tracerPidString = "TracerPid:";
|
||||
const size_t tracerPidOffset = processStatusView.find(tracerPidString);
|
||||
if (tracerPidOffset == AZStd::string_view::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (size_t i = tracerPidOffset + tracerPidString.length(); i < numRead; ++i)
|
||||
{
|
||||
if (!::isspace(processStatusView[i]))
|
||||
{
|
||||
AZ::IO::SystemFile processStatusFile;
|
||||
if (!processStatusFile.Open("/proc/self/status", AZ::IO::SystemFile::SF_OPEN_READ_ONLY))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
char buffer[4096];
|
||||
AZ::IO::SystemFile::SizeType numRead = processStatusFile.Read(sizeof(buffer), buffer);
|
||||
|
||||
const AZStd::string_view processStatusView(buffer, buffer + numRead);
|
||||
constexpr AZStd::string_view tracerPidString = "TracerPid:";
|
||||
const size_t tracerPidOffset = processStatusView.find(tracerPidString);
|
||||
if (tracerPidOffset == AZStd::string_view::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (size_t i = tracerPidOffset + tracerPidString.length(); i < numRead; ++i)
|
||||
{
|
||||
if (!::isspace(processStatusView[i]))
|
||||
{
|
||||
return processStatusView[i] != '0';
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsDebuggerPresent()
|
||||
{
|
||||
static bool s_detectionPerformed = false;
|
||||
static bool s_debuggerDetected = false;
|
||||
if (!s_detectionPerformed)
|
||||
{
|
||||
s_debuggerDetected = performDebuggerDetection();
|
||||
s_detectionPerformed = true;
|
||||
}
|
||||
return s_debuggerDetected;
|
||||
}
|
||||
|
||||
bool AttachDebugger()
|
||||
{
|
||||
// Not supported yet
|
||||
AZ_Assert(false, "AttachDebugger() is not supported for Unix platform yet");
|
||||
return false;
|
||||
}
|
||||
|
||||
void HandleExceptions(bool)
|
||||
{}
|
||||
|
||||
void DebugBreak()
|
||||
{
|
||||
raise(SIGINT);
|
||||
}
|
||||
#endif // AZ_ENABLE_DEBUG_TOOLS
|
||||
|
||||
void Terminate(int exitCode)
|
||||
{
|
||||
_exit(exitCode);
|
||||
return processStatusView[i] != '0';
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsDebuggerPresent()
|
||||
{
|
||||
static bool s_detectionPerformed = false;
|
||||
static bool s_debuggerDetected = false;
|
||||
if (!s_detectionPerformed)
|
||||
{
|
||||
s_debuggerDetected = performDebuggerDetection();
|
||||
s_detectionPerformed = true;
|
||||
}
|
||||
return s_debuggerDetected;
|
||||
}
|
||||
|
||||
bool AttachDebugger()
|
||||
{
|
||||
// Not supported yet
|
||||
AZ_Assert(false, "AttachDebugger() is not supported for Unix platform yet");
|
||||
return false;
|
||||
}
|
||||
|
||||
void HandleExceptions(bool)
|
||||
{}
|
||||
|
||||
void DebugBreak()
|
||||
{
|
||||
raise(SIGINT);
|
||||
}
|
||||
#endif // AZ_ENABLE_DEBUG_TOOLS
|
||||
|
||||
void Terminate(int exitCode)
|
||||
{
|
||||
_exit(exitCode);
|
||||
}
|
||||
} // namespace AZ::Debug::Platform
|
||||
|
||||
+58
-64
@@ -8,82 +8,76 @@
|
||||
|
||||
#include "SystemFileUtils_UnixLike.h"
|
||||
|
||||
namespace AZ
|
||||
namespace AZ::IO::Internal
|
||||
{
|
||||
namespace IO
|
||||
bool FormatAndPeelOffWildCardExtension(const char* sourcePath, char* filePath, size_t filePathSize, char* extensionPath, size_t extensionSize, bool keepWildcard)
|
||||
{
|
||||
namespace Internal
|
||||
if (sourcePath == nullptr || filePath == nullptr || extensionPath == nullptr || filePathSize == 0 || extensionSize == 0)
|
||||
{
|
||||
bool FormatAndPeelOffWildCardExtension(const char* sourcePath, char* filePath, size_t filePathSize, char* extensionPath, size_t extensionSize, bool keepWildcard)
|
||||
AZ_Error("AZ::IO::Internal", false, "FormatAndPeelOffWildCardExtension: One or more parameters was invalid.");
|
||||
return false;
|
||||
}
|
||||
const char* pSrcPath = sourcePath;
|
||||
char* pDestPath = filePath;
|
||||
size_t destinationSize = filePathSize;
|
||||
unsigned numFileChars = 0;
|
||||
unsigned numExtensionChars = 0;
|
||||
unsigned* pNumDestChars = &numFileChars;
|
||||
bool bIsWildcardExtension = false;
|
||||
while (*pSrcPath)
|
||||
{
|
||||
char srcChar = *pSrcPath++;
|
||||
|
||||
// Skip '*' and '.'
|
||||
if ((!bIsWildcardExtension && srcChar != '*') || (bIsWildcardExtension && srcChar != '.' && (keepWildcard || srcChar != '*')))
|
||||
{
|
||||
if (sourcePath == nullptr || filePath == nullptr || extensionPath == nullptr || filePathSize == 0 || extensionSize == 0)
|
||||
unsigned numChars = *pNumDestChars;
|
||||
pDestPath[numChars++] = srcChar;
|
||||
*pNumDestChars = numChars;
|
||||
|
||||
--destinationSize;
|
||||
if (destinationSize == 0)
|
||||
{
|
||||
AZ_Error("AZ::IO::Internal", false, "FormatAndPeelOffWildCardExtension: One or more parameters was invalid.");
|
||||
AZ_Error(
|
||||
"AZ::IO::Internal",
|
||||
false,
|
||||
"Error splitting sourcePath '%s' into filePath and extension, %s length is larger than storage size %d.",
|
||||
sourcePath,
|
||||
bIsWildcardExtension ? "extensionPath" : "filePath",
|
||||
bIsWildcardExtension ? extensionSize : filePathSize);
|
||||
return false;
|
||||
}
|
||||
const char* pSrcPath = sourcePath;
|
||||
char* pDestPath = filePath;
|
||||
size_t destinationSize = filePathSize;
|
||||
unsigned numFileChars = 0;
|
||||
unsigned numExtensionChars = 0;
|
||||
unsigned* pNumDestChars = &numFileChars;
|
||||
bool bIsWildcardExtension = false;
|
||||
while (*pSrcPath)
|
||||
}
|
||||
// Wild-card extension is separate
|
||||
if (srcChar == '*')
|
||||
{
|
||||
bIsWildcardExtension = true;
|
||||
pDestPath = extensionPath;
|
||||
destinationSize = extensionSize;
|
||||
pNumDestChars = &numExtensionChars;
|
||||
if (keepWildcard)
|
||||
{
|
||||
char srcChar = *pSrcPath++;
|
||||
unsigned numChars = *pNumDestChars;
|
||||
pDestPath[numChars++] = srcChar;
|
||||
*pNumDestChars = numChars;
|
||||
|
||||
// Skip '*' and '.'
|
||||
if ((!bIsWildcardExtension && srcChar != '*') || (bIsWildcardExtension && srcChar != '.' && (keepWildcard || srcChar != '*')))
|
||||
--destinationSize;
|
||||
if (destinationSize == 0)
|
||||
{
|
||||
unsigned numChars = *pNumDestChars;
|
||||
pDestPath[numChars++] = srcChar;
|
||||
*pNumDestChars = numChars;
|
||||
|
||||
--destinationSize;
|
||||
if (destinationSize == 0)
|
||||
{
|
||||
AZ_Error(
|
||||
"AZ::IO::Internal",
|
||||
false,
|
||||
"Error splitting sourcePath '%s' into filePath and extension, %s length is larger than storage size %d.",
|
||||
sourcePath,
|
||||
bIsWildcardExtension ? "extensionPath" : "filePath",
|
||||
bIsWildcardExtension ? extensionSize : filePathSize);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Wild-card extension is separate
|
||||
if (srcChar == '*')
|
||||
{
|
||||
bIsWildcardExtension = true;
|
||||
pDestPath = extensionPath;
|
||||
destinationSize = extensionSize;
|
||||
pNumDestChars = &numExtensionChars;
|
||||
if (keepWildcard)
|
||||
{
|
||||
unsigned numChars = *pNumDestChars;
|
||||
pDestPath[numChars++] = srcChar;
|
||||
*pNumDestChars = numChars;
|
||||
|
||||
--destinationSize;
|
||||
if (destinationSize == 0)
|
||||
{
|
||||
AZ_Error(
|
||||
"AZ::IO::Internal",
|
||||
false,
|
||||
"Error splitting sourcePath '%s' into filePath and extension, extensionPath length is larger than storage size %d.",
|
||||
sourcePath,
|
||||
extensionSize);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
AZ_Error(
|
||||
"AZ::IO::Internal",
|
||||
false,
|
||||
"Error splitting sourcePath '%s' into filePath and extension, extensionPath length is larger than storage size %d.",
|
||||
sourcePath,
|
||||
extensionSize);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Close strings
|
||||
filePath[numFileChars] = 0;
|
||||
extensionPath[numExtensionChars] = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Close strings
|
||||
filePath[numFileChars] = 0;
|
||||
extensionPath[numExtensionChars] = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} // namespace AZ::IO::Internal
|
||||
|
||||
@@ -14,31 +14,28 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace AZ
|
||||
namespace AZ::Platform
|
||||
{
|
||||
namespace Platform
|
||||
ProcessId GetCurrentProcessId()
|
||||
{
|
||||
ProcessId GetCurrentProcessId()
|
||||
{
|
||||
return static_cast<ProcessId>(::getpid());
|
||||
}
|
||||
return static_cast<ProcessId>(::getpid());
|
||||
}
|
||||
|
||||
MachineId GetLocalMachineId()
|
||||
MachineId GetLocalMachineId()
|
||||
{
|
||||
if (s_machineId == 0)
|
||||
{
|
||||
// In specialized server situations, SetLocalMachineId() should be used, with whatever criteria works best in that environment
|
||||
// A proper implementation for each supported system will be needed instead of this temporary measure to avoid collision in the small scale.
|
||||
// On a larger scale, the odds of two people getting in here at the same millisecond will go up drastically, and we'll have the same issue again,
|
||||
// though far less reproducible, for duplicated EntityId's across a network.
|
||||
s_machineId = static_cast<AZ::u32>(AZStd::GetTimeUTCMilliSecond() & 0xffffffff);
|
||||
if (s_machineId == 0)
|
||||
{
|
||||
// In specialized server situations, SetLocalMachineId() should be used, with whatever criteria works best in that environment
|
||||
// A proper implementation for each supported system will be needed instead of this temporary measure to avoid collision in the small scale.
|
||||
// On a larger scale, the odds of two people getting in here at the same millisecond will go up drastically, and we'll have the same issue again,
|
||||
// though far less reproducible, for duplicated EntityId's across a network.
|
||||
s_machineId = static_cast<AZ::u32>(AZStd::GetTimeUTCMilliSecond() & 0xffffffff);
|
||||
if (s_machineId == 0)
|
||||
{
|
||||
s_machineId = 1;
|
||||
AZ_Warning("System", false, "0 machine ID is reserved!");
|
||||
}
|
||||
s_machineId = 1;
|
||||
AZ_Warning("System", false, "0 machine ID is reserved!");
|
||||
}
|
||||
return s_machineId;
|
||||
}
|
||||
} // namespace Platform
|
||||
}
|
||||
return s_machineId;
|
||||
}
|
||||
} // namespace AZ::Platform
|
||||
|
||||
+327
-330
@@ -18,365 +18,362 @@
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define closesocket(_s) close(_s)
|
||||
#define GetInternalSocketError errno
|
||||
typedef int SOCKET;
|
||||
typedef AZ::u32 AZSOCKLEN;
|
||||
using SOCKET = int;
|
||||
using AZSOCKLEN = AZ::u32;
|
||||
|
||||
namespace AZ
|
||||
namespace AZ::AzSock
|
||||
{
|
||||
namespace AzSock
|
||||
AZ::s32 TranslateOSError(AZ::s32 oserror)
|
||||
{
|
||||
AZ::s32 TranslateOSError(AZ::s32 oserror)
|
||||
{
|
||||
AZ::s32 error;
|
||||
AZ::s32 error;
|
||||
|
||||
#define TRANSLATE(_from, _to) case (_from): error = static_cast<AZ::s32>(_to); break;
|
||||
|
||||
switch (oserror)
|
||||
{
|
||||
TRANSLATE(0, AzSockError::eASE_NO_ERROR);
|
||||
TRANSLATE(EACCES, AzSockError::eASE_EACCES);
|
||||
TRANSLATE(EADDRINUSE, AzSockError::eASE_EADDRINUSE);
|
||||
TRANSLATE(EADDRNOTAVAIL, AzSockError::eASE_EADDRNOTAVAIL);
|
||||
TRANSLATE(EAFNOSUPPORT, AzSockError::eASE_EAFNOSUPPORT);
|
||||
TRANSLATE(EALREADY, AzSockError::eASE_EALREADY);
|
||||
TRANSLATE(EBADF, AzSockError::eASE_EBADF);
|
||||
TRANSLATE(ECONNABORTED, AzSockError::eASE_ECONNABORTED);
|
||||
TRANSLATE(ECONNREFUSED, AzSockError::eASE_ECONNREFUSED);
|
||||
TRANSLATE(ECONNRESET, AzSockError::eASE_ECONNRESET);
|
||||
TRANSLATE(EFAULT, AzSockError::eASE_EFAULT);
|
||||
TRANSLATE(EHOSTDOWN, AzSockError::eASE_EHOSTDOWN);
|
||||
TRANSLATE(EINPROGRESS, AzSockError::eASE_EINPROGRESS);
|
||||
TRANSLATE(EINTR, AzSockError::eASE_EINTR);
|
||||
TRANSLATE(EINVAL, AzSockError::eASE_EINVAL);
|
||||
TRANSLATE(EISCONN, AzSockError::eASE_EISCONN);
|
||||
TRANSLATE(EMFILE, AzSockError::eASE_EMFILE);
|
||||
TRANSLATE(EMSGSIZE, AzSockError::eASE_EMSGSIZE);
|
||||
TRANSLATE(ENETUNREACH, AzSockError::eASE_ENETUNREACH);
|
||||
TRANSLATE(ENOBUFS, AzSockError::eASE_ENOBUFS);
|
||||
TRANSLATE(ENOPROTOOPT, AzSockError::eASE_ENOPROTOOPT);
|
||||
TRANSLATE(ENOTCONN, AzSockError::eASE_ENOTCONN);
|
||||
TRANSLATE(EOPNOTSUPP, AzSockError::eASE_EOPNOTSUPP);
|
||||
TRANSLATE(EPROTONOSUPPORT, AzSockError::eASE_EAFNOSUPPORT);
|
||||
TRANSLATE(ETIMEDOUT, AzSockError::eASE_ETIMEDOUT);
|
||||
TRANSLATE(ETOOMANYREFS, AzSockError::eASE_ETOOMANYREFS);
|
||||
TRANSLATE(EWOULDBLOCK, AzSockError::eASE_EWOULDBLOCK);
|
||||
switch (oserror)
|
||||
{
|
||||
TRANSLATE(0, AzSockError::eASE_NO_ERROR);
|
||||
TRANSLATE(EACCES, AzSockError::eASE_EACCES);
|
||||
TRANSLATE(EADDRINUSE, AzSockError::eASE_EADDRINUSE);
|
||||
TRANSLATE(EADDRNOTAVAIL, AzSockError::eASE_EADDRNOTAVAIL);
|
||||
TRANSLATE(EAFNOSUPPORT, AzSockError::eASE_EAFNOSUPPORT);
|
||||
TRANSLATE(EALREADY, AzSockError::eASE_EALREADY);
|
||||
TRANSLATE(EBADF, AzSockError::eASE_EBADF);
|
||||
TRANSLATE(ECONNABORTED, AzSockError::eASE_ECONNABORTED);
|
||||
TRANSLATE(ECONNREFUSED, AzSockError::eASE_ECONNREFUSED);
|
||||
TRANSLATE(ECONNRESET, AzSockError::eASE_ECONNRESET);
|
||||
TRANSLATE(EFAULT, AzSockError::eASE_EFAULT);
|
||||
TRANSLATE(EHOSTDOWN, AzSockError::eASE_EHOSTDOWN);
|
||||
TRANSLATE(EINPROGRESS, AzSockError::eASE_EINPROGRESS);
|
||||
TRANSLATE(EINTR, AzSockError::eASE_EINTR);
|
||||
TRANSLATE(EINVAL, AzSockError::eASE_EINVAL);
|
||||
TRANSLATE(EISCONN, AzSockError::eASE_EISCONN);
|
||||
TRANSLATE(EMFILE, AzSockError::eASE_EMFILE);
|
||||
TRANSLATE(EMSGSIZE, AzSockError::eASE_EMSGSIZE);
|
||||
TRANSLATE(ENETUNREACH, AzSockError::eASE_ENETUNREACH);
|
||||
TRANSLATE(ENOBUFS, AzSockError::eASE_ENOBUFS);
|
||||
TRANSLATE(ENOPROTOOPT, AzSockError::eASE_ENOPROTOOPT);
|
||||
TRANSLATE(ENOTCONN, AzSockError::eASE_ENOTCONN);
|
||||
TRANSLATE(EOPNOTSUPP, AzSockError::eASE_EOPNOTSUPP);
|
||||
TRANSLATE(EPROTONOSUPPORT, AzSockError::eASE_EAFNOSUPPORT);
|
||||
TRANSLATE(ETIMEDOUT, AzSockError::eASE_ETIMEDOUT);
|
||||
TRANSLATE(ETOOMANYREFS, AzSockError::eASE_ETOOMANYREFS);
|
||||
TRANSLATE(EWOULDBLOCK, AzSockError::eASE_EWOULDBLOCK);
|
||||
|
||||
default:
|
||||
AZ_TracePrintf("AzSock", "AzSocket could not translate OS error code %x, treating as miscellaneous.\n", oserror);
|
||||
error = static_cast<AZ::s32>(AzSockError::eASE_MISC_ERROR);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
AZ_TracePrintf("AzSock", "AzSocket could not translate OS error code %x, treating as miscellaneous.\n", oserror);
|
||||
error = static_cast<AZ::s32>(AzSockError::eASE_MISC_ERROR);
|
||||
break;
|
||||
}
|
||||
|
||||
#undef TRANSLATE
|
||||
|
||||
return error;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
AZ::s32 TranslateSocketOption(AzSocketOption opt)
|
||||
{
|
||||
AZ::s32 value;
|
||||
AZ::s32 TranslateSocketOption(AzSocketOption opt)
|
||||
{
|
||||
AZ::s32 value;
|
||||
|
||||
#define TRANSLATE(_from, _to) case (_from): value = (_to); break;
|
||||
|
||||
switch (opt)
|
||||
{
|
||||
TRANSLATE(AzSocketOption::REUSEADDR, SO_REUSEADDR);
|
||||
TRANSLATE(AzSocketOption::KEEPALIVE, SO_KEEPALIVE);
|
||||
TRANSLATE(AzSocketOption::LINGER, SO_LINGER);
|
||||
switch (opt)
|
||||
{
|
||||
TRANSLATE(AzSocketOption::REUSEADDR, SO_REUSEADDR);
|
||||
TRANSLATE(AzSocketOption::KEEPALIVE, SO_KEEPALIVE);
|
||||
TRANSLATE(AzSocketOption::LINGER, SO_LINGER);
|
||||
|
||||
default:
|
||||
AZ_TracePrintf("AzSock", "AzSocket option %x not yet supported", opt);
|
||||
value = 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
AZ_TracePrintf("AzSock", "AzSocket option %x not yet supported", opt);
|
||||
value = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
#undef TRANSLATE
|
||||
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
AZSOCKET HandleInvalidSocket(SOCKET sock)
|
||||
AZSOCKET HandleInvalidSocket(SOCKET sock)
|
||||
{
|
||||
AZSOCKET azsock = static_cast<AZSOCKET>(sock);
|
||||
if (sock == INVALID_SOCKET)
|
||||
{
|
||||
AZSOCKET azsock = static_cast<AZSOCKET>(sock);
|
||||
if (sock == INVALID_SOCKET)
|
||||
{
|
||||
azsock = TranslateOSError(GetInternalSocketError);
|
||||
}
|
||||
return azsock;
|
||||
azsock = TranslateOSError(GetInternalSocketError);
|
||||
}
|
||||
return azsock;
|
||||
}
|
||||
|
||||
AZ::s32 HandleSocketError(AZ::s32 socketError)
|
||||
AZ::s32 HandleSocketError(AZ::s32 socketError)
|
||||
{
|
||||
if (socketError == SOCKET_ERROR)
|
||||
{
|
||||
if (socketError == SOCKET_ERROR)
|
||||
{
|
||||
socketError = TranslateOSError(GetInternalSocketError);
|
||||
}
|
||||
return socketError;
|
||||
socketError = TranslateOSError(GetInternalSocketError);
|
||||
}
|
||||
return socketError;
|
||||
}
|
||||
|
||||
const char* GetStringForError(AZ::s32 errorNumber)
|
||||
{
|
||||
AzSockError errorCode = AzSockError(errorNumber);
|
||||
const char* GetStringForError(AZ::s32 errorNumber)
|
||||
{
|
||||
AzSockError errorCode = AzSockError(errorNumber);
|
||||
|
||||
#define CASE_RETSTRING(errorEnum) case errorEnum: { return #errorEnum; }
|
||||
|
||||
switch (errorCode)
|
||||
{
|
||||
CASE_RETSTRING(AzSockError::eASE_NO_ERROR);
|
||||
CASE_RETSTRING(AzSockError::eASE_SOCKET_INVALID);
|
||||
CASE_RETSTRING(AzSockError::eASE_EACCES);
|
||||
CASE_RETSTRING(AzSockError::eASE_EADDRINUSE);
|
||||
CASE_RETSTRING(AzSockError::eASE_EADDRNOTAVAIL);
|
||||
CASE_RETSTRING(AzSockError::eASE_EAFNOSUPPORT);
|
||||
CASE_RETSTRING(AzSockError::eASE_EALREADY);
|
||||
CASE_RETSTRING(AzSockError::eASE_EBADF);
|
||||
CASE_RETSTRING(AzSockError::eASE_ECONNABORTED);
|
||||
CASE_RETSTRING(AzSockError::eASE_ECONNREFUSED);
|
||||
CASE_RETSTRING(AzSockError::eASE_ECONNRESET);
|
||||
CASE_RETSTRING(AzSockError::eASE_EFAULT);
|
||||
CASE_RETSTRING(AzSockError::eASE_EHOSTDOWN);
|
||||
CASE_RETSTRING(AzSockError::eASE_EINPROGRESS);
|
||||
CASE_RETSTRING(AzSockError::eASE_EINTR);
|
||||
CASE_RETSTRING(AzSockError::eASE_EINVAL);
|
||||
CASE_RETSTRING(AzSockError::eASE_EISCONN);
|
||||
CASE_RETSTRING(AzSockError::eASE_EMFILE);
|
||||
CASE_RETSTRING(AzSockError::eASE_EMSGSIZE);
|
||||
CASE_RETSTRING(AzSockError::eASE_ENETUNREACH);
|
||||
CASE_RETSTRING(AzSockError::eASE_ENOBUFS);
|
||||
CASE_RETSTRING(AzSockError::eASE_ENOPROTOOPT);
|
||||
CASE_RETSTRING(AzSockError::eASE_ENOTCONN);
|
||||
CASE_RETSTRING(AzSockError::eASE_ENOTINITIALISED);
|
||||
CASE_RETSTRING(AzSockError::eASE_EOPNOTSUPP);
|
||||
CASE_RETSTRING(AzSockError::eASE_EPIPE);
|
||||
CASE_RETSTRING(AzSockError::eASE_EPROTONOSUPPORT);
|
||||
CASE_RETSTRING(AzSockError::eASE_ETIMEDOUT);
|
||||
CASE_RETSTRING(AzSockError::eASE_ETOOMANYREFS);
|
||||
CASE_RETSTRING(AzSockError::eASE_EWOULDBLOCK);
|
||||
CASE_RETSTRING(AzSockError::eASE_EWOULDBLOCK_CONN);
|
||||
CASE_RETSTRING(AzSockError::eASE_MISC_ERROR);
|
||||
}
|
||||
switch (errorCode)
|
||||
{
|
||||
CASE_RETSTRING(AzSockError::eASE_NO_ERROR);
|
||||
CASE_RETSTRING(AzSockError::eASE_SOCKET_INVALID);
|
||||
CASE_RETSTRING(AzSockError::eASE_EACCES);
|
||||
CASE_RETSTRING(AzSockError::eASE_EADDRINUSE);
|
||||
CASE_RETSTRING(AzSockError::eASE_EADDRNOTAVAIL);
|
||||
CASE_RETSTRING(AzSockError::eASE_EAFNOSUPPORT);
|
||||
CASE_RETSTRING(AzSockError::eASE_EALREADY);
|
||||
CASE_RETSTRING(AzSockError::eASE_EBADF);
|
||||
CASE_RETSTRING(AzSockError::eASE_ECONNABORTED);
|
||||
CASE_RETSTRING(AzSockError::eASE_ECONNREFUSED);
|
||||
CASE_RETSTRING(AzSockError::eASE_ECONNRESET);
|
||||
CASE_RETSTRING(AzSockError::eASE_EFAULT);
|
||||
CASE_RETSTRING(AzSockError::eASE_EHOSTDOWN);
|
||||
CASE_RETSTRING(AzSockError::eASE_EINPROGRESS);
|
||||
CASE_RETSTRING(AzSockError::eASE_EINTR);
|
||||
CASE_RETSTRING(AzSockError::eASE_EINVAL);
|
||||
CASE_RETSTRING(AzSockError::eASE_EISCONN);
|
||||
CASE_RETSTRING(AzSockError::eASE_EMFILE);
|
||||
CASE_RETSTRING(AzSockError::eASE_EMSGSIZE);
|
||||
CASE_RETSTRING(AzSockError::eASE_ENETUNREACH);
|
||||
CASE_RETSTRING(AzSockError::eASE_ENOBUFS);
|
||||
CASE_RETSTRING(AzSockError::eASE_ENOPROTOOPT);
|
||||
CASE_RETSTRING(AzSockError::eASE_ENOTCONN);
|
||||
CASE_RETSTRING(AzSockError::eASE_ENOTINITIALISED);
|
||||
CASE_RETSTRING(AzSockError::eASE_EOPNOTSUPP);
|
||||
CASE_RETSTRING(AzSockError::eASE_EPIPE);
|
||||
CASE_RETSTRING(AzSockError::eASE_EPROTONOSUPPORT);
|
||||
CASE_RETSTRING(AzSockError::eASE_ETIMEDOUT);
|
||||
CASE_RETSTRING(AzSockError::eASE_ETOOMANYREFS);
|
||||
CASE_RETSTRING(AzSockError::eASE_EWOULDBLOCK);
|
||||
CASE_RETSTRING(AzSockError::eASE_EWOULDBLOCK_CONN);
|
||||
CASE_RETSTRING(AzSockError::eASE_MISC_ERROR);
|
||||
}
|
||||
|
||||
#undef CASE_RETSTRING
|
||||
|
||||
return "(invalid)";
|
||||
}
|
||||
|
||||
AZ::u32 HostToNetLong(AZ::u32 hstLong)
|
||||
{
|
||||
return htonl(hstLong);
|
||||
}
|
||||
|
||||
AZ::u32 NetToHostLong(AZ::u32 netLong)
|
||||
{
|
||||
return ntohl(netLong);
|
||||
}
|
||||
|
||||
AZ::u16 HostToNetShort(AZ::u16 hstShort)
|
||||
{
|
||||
return htons(hstShort);
|
||||
}
|
||||
|
||||
AZ::u16 NetToHostShort(AZ::u16 netShort)
|
||||
{
|
||||
return ntohs(netShort);
|
||||
}
|
||||
|
||||
AZ::s32 GetHostName(AZStd::string& hostname)
|
||||
{
|
||||
AZ::s32 result = 0;
|
||||
hostname.clear();
|
||||
char name[256];
|
||||
result = HandleSocketError(gethostname(name, AZ_ARRAY_SIZE(name)));
|
||||
if (result == static_cast<AZ::s32>(AzSockError::eASE_NO_ERROR))
|
||||
{
|
||||
hostname = name;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
AZSOCKET Socket()
|
||||
{
|
||||
return Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
}
|
||||
|
||||
AZSOCKET Socket(AZ::s32 af, AZ::s32 type, AZ::s32 protocol)
|
||||
{
|
||||
return HandleInvalidSocket(socket(af, type, protocol));
|
||||
}
|
||||
|
||||
AZ::s32 SetSockOpt(AZSOCKET sock, AZ::s32 level, AZ::s32 optname, const char* optval, AZ::s32 optlen)
|
||||
{
|
||||
AZSOCKLEN length(optlen);
|
||||
return HandleSocketError(setsockopt(sock, level, optname, optval, length));
|
||||
}
|
||||
|
||||
AZ::s32 SetSocketOption(AZSOCKET sock, AzSocketOption opt, bool enable)
|
||||
{
|
||||
AZ::u32 val = enable ? 1 : 0;
|
||||
return SetSockOpt(sock, SOL_SOCKET, TranslateSocketOption(opt), reinterpret_cast<const char*>(&val), sizeof(val));
|
||||
}
|
||||
|
||||
AZ::s32 EnableTCPNoDelay(AZSOCKET sock, bool enable)
|
||||
{
|
||||
AZ::u32 val = enable ? 1 : 0;
|
||||
return SetSockOpt(sock, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<const char*>(&val), sizeof(val));
|
||||
}
|
||||
|
||||
AZ::s32 SetSocketBlockingMode(AZSOCKET sock, bool blocking)
|
||||
{
|
||||
AZ::s32 flags = ::fcntl(sock, F_GETFL);
|
||||
flags &= ~O_NONBLOCK;
|
||||
flags |= (blocking ? 0 : O_NONBLOCK);
|
||||
return ::fcntl(sock, F_SETFL, flags);
|
||||
}
|
||||
|
||||
AZ::s32 CloseSocket(AZSOCKET sock)
|
||||
{
|
||||
return HandleSocketError(closesocket(sock));
|
||||
}
|
||||
|
||||
AZ::s32 Shutdown(AZSOCKET sock, AZ::s32 how)
|
||||
{
|
||||
return HandleSocketError(shutdown(sock, how));
|
||||
}
|
||||
|
||||
AZ::s32 GetSockName(AZSOCKET sock, AzSocketAddress& addr)
|
||||
{
|
||||
AZSOCKADDR sAddr;
|
||||
AZSOCKLEN sAddrLen = sizeof(AZSOCKADDR);
|
||||
memset(&sAddr, 0, sAddrLen);
|
||||
AZ::s32 result = HandleSocketError(getsockname(sock, &sAddr, &sAddrLen));
|
||||
addr = sAddr;
|
||||
return result;
|
||||
}
|
||||
|
||||
AZ::s32 Connect(AZSOCKET sock, const AzSocketAddress& addr)
|
||||
{
|
||||
AZ::s32 err = HandleSocketError(connect(sock, addr.GetTargetAddress(), sizeof(AZSOCKADDR_IN)));
|
||||
if (err == static_cast<AZ::s32>(AzSockError::eASE_EINPROGRESS))
|
||||
{
|
||||
err = static_cast<AZ::s32>(AzSockError::eASE_EWOULDBLOCK_CONN);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
AZ::s32 Listen(AZSOCKET sock, AZ::s32 backlog)
|
||||
{
|
||||
return HandleSocketError(listen(sock, backlog));
|
||||
}
|
||||
|
||||
AZSOCKET Accept(AZSOCKET sock, AzSocketAddress& addr)
|
||||
{
|
||||
AZSOCKADDR sAddr;
|
||||
AZSOCKLEN sAddrLen = sizeof(AZSOCKADDR);
|
||||
memset(&sAddr, 0, sAddrLen);
|
||||
AZSOCKET outSock = HandleInvalidSocket(accept(sock, &sAddr, &sAddrLen));
|
||||
addr = sAddr;
|
||||
return outSock;
|
||||
}
|
||||
|
||||
AZ::s32 Send(AZSOCKET sock, const char* buf, AZ::s32 len, AZ::s32 flags)
|
||||
{
|
||||
AZ::s32 msgNoSignal = MSG_NOSIGNAL;
|
||||
return HandleSocketError(send(sock, buf, len, flags | msgNoSignal));
|
||||
}
|
||||
|
||||
AZ::s32 Recv(AZSOCKET sock, char* buf, AZ::s32 len, AZ::s32 flags)
|
||||
{
|
||||
return HandleSocketError(recv(sock, buf, len, flags));
|
||||
}
|
||||
|
||||
AZ::s32 Bind(AZSOCKET sock, const AzSocketAddress& addr)
|
||||
{
|
||||
return HandleSocketError(bind(sock, addr.GetTargetAddress(), sizeof(AZSOCKADDR_IN)));
|
||||
}
|
||||
|
||||
AZ::s32 Select(AZSOCKET sock, AZFD_SET* readfdsock, AZFD_SET* writefdsock, AZFD_SET* exceptfdsock, AZTIMEVAL* timeout)
|
||||
{
|
||||
return HandleSocketError(::select(sock + 1, readfdsock, writefdsock, exceptfdsock, timeout));
|
||||
}
|
||||
|
||||
AZ::s32 IsRecvPending(AZSOCKET sock, AZTIMEVAL* timeout)
|
||||
{
|
||||
AZFD_SET readSet;
|
||||
FD_ZERO(&readSet);
|
||||
FD_SET(sock, &readSet);
|
||||
|
||||
AZ::s32 ret = Select(sock, &readSet, nullptr, nullptr, timeout);
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = FD_ISSET(sock, &readSet);
|
||||
if (ret != 0)
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
AZ::s32 WaitForWritableSocket(AZSOCKET sock, AZTIMEVAL* timeout)
|
||||
{
|
||||
AZFD_SET writeSet;
|
||||
FD_ZERO(&writeSet);
|
||||
FD_SET(sock, &writeSet);
|
||||
|
||||
AZ::s32 ret = Select(sock, nullptr, &writeSet, nullptr, timeout);
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = FD_ISSET(sock, &writeSet);
|
||||
if (ret != 0)
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
AZ::s32 Startup()
|
||||
{
|
||||
return static_cast<AZ::s32>(AzSockError::eASE_NO_ERROR);
|
||||
}
|
||||
|
||||
AZ::s32 Cleanup()
|
||||
{
|
||||
return static_cast<AZ::s32>(AzSockError::eASE_NO_ERROR);
|
||||
}
|
||||
|
||||
bool ResolveAddress(const AZStd::string& ip, AZ::u16 port, AZSOCKADDR_IN& socketAddress)
|
||||
{
|
||||
bool foundAddr = false;
|
||||
addrinfo hints;
|
||||
memset(&hints, 0, sizeof(addrinfo));
|
||||
addrinfo* addrInfo;
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
char strPort[8];
|
||||
azsnprintf(strPort, AZ_ARRAY_SIZE(strPort), "%d", port);
|
||||
|
||||
const char* address = ip.c_str();
|
||||
if (address && strlen(address) == 0) // getaddrinfo doesn't accept empty string
|
||||
{
|
||||
address = nullptr;
|
||||
}
|
||||
|
||||
AZ::s32 err = HandleSocketError(getaddrinfo(address, strPort, &hints, &addrInfo));
|
||||
if (err == 0) // eASE_NO_ERROR
|
||||
{
|
||||
if (addrInfo->ai_family == AF_INET)
|
||||
{
|
||||
socketAddress = *reinterpret_cast<const AZSOCKADDR_IN*>(addrInfo->ai_addr);
|
||||
foundAddr = true;
|
||||
}
|
||||
|
||||
freeaddrinfo(addrInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Assert(false, "AzSocketAddress could not resolve address %s with port %d. (reason - %s)", ip.c_str(), port, GetStringForError(err));
|
||||
}
|
||||
return foundAddr;
|
||||
}
|
||||
return "(invalid)";
|
||||
}
|
||||
}
|
||||
|
||||
AZ::u32 HostToNetLong(AZ::u32 hstLong)
|
||||
{
|
||||
return htonl(hstLong);
|
||||
}
|
||||
|
||||
AZ::u32 NetToHostLong(AZ::u32 netLong)
|
||||
{
|
||||
return ntohl(netLong);
|
||||
}
|
||||
|
||||
AZ::u16 HostToNetShort(AZ::u16 hstShort)
|
||||
{
|
||||
return htons(hstShort);
|
||||
}
|
||||
|
||||
AZ::u16 NetToHostShort(AZ::u16 netShort)
|
||||
{
|
||||
return ntohs(netShort);
|
||||
}
|
||||
|
||||
AZ::s32 GetHostName(AZStd::string& hostname)
|
||||
{
|
||||
AZ::s32 result = 0;
|
||||
hostname.clear();
|
||||
char name[256];
|
||||
result = HandleSocketError(gethostname(name, AZ_ARRAY_SIZE(name)));
|
||||
if (result == static_cast<AZ::s32>(AzSockError::eASE_NO_ERROR))
|
||||
{
|
||||
hostname = name;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
AZSOCKET Socket()
|
||||
{
|
||||
return Socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
}
|
||||
|
||||
AZSOCKET Socket(AZ::s32 af, AZ::s32 type, AZ::s32 protocol)
|
||||
{
|
||||
return HandleInvalidSocket(socket(af, type, protocol));
|
||||
}
|
||||
|
||||
AZ::s32 SetSockOpt(AZSOCKET sock, AZ::s32 level, AZ::s32 optname, const char* optval, AZ::s32 optlen)
|
||||
{
|
||||
AZSOCKLEN length(optlen);
|
||||
return HandleSocketError(setsockopt(sock, level, optname, optval, length));
|
||||
}
|
||||
|
||||
AZ::s32 SetSocketOption(AZSOCKET sock, AzSocketOption opt, bool enable)
|
||||
{
|
||||
AZ::u32 val = enable ? 1 : 0;
|
||||
return SetSockOpt(sock, SOL_SOCKET, TranslateSocketOption(opt), reinterpret_cast<const char*>(&val), sizeof(val));
|
||||
}
|
||||
|
||||
AZ::s32 EnableTCPNoDelay(AZSOCKET sock, bool enable)
|
||||
{
|
||||
AZ::u32 val = enable ? 1 : 0;
|
||||
return SetSockOpt(sock, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<const char*>(&val), sizeof(val));
|
||||
}
|
||||
|
||||
AZ::s32 SetSocketBlockingMode(AZSOCKET sock, bool blocking)
|
||||
{
|
||||
AZ::s32 flags = ::fcntl(sock, F_GETFL);
|
||||
flags &= ~O_NONBLOCK;
|
||||
flags |= (blocking ? 0 : O_NONBLOCK);
|
||||
return ::fcntl(sock, F_SETFL, flags);
|
||||
}
|
||||
|
||||
AZ::s32 CloseSocket(AZSOCKET sock)
|
||||
{
|
||||
return HandleSocketError(closesocket(sock));
|
||||
}
|
||||
|
||||
AZ::s32 Shutdown(AZSOCKET sock, AZ::s32 how)
|
||||
{
|
||||
return HandleSocketError(shutdown(sock, how));
|
||||
}
|
||||
|
||||
AZ::s32 GetSockName(AZSOCKET sock, AzSocketAddress& addr)
|
||||
{
|
||||
AZSOCKADDR sAddr;
|
||||
AZSOCKLEN sAddrLen = sizeof(AZSOCKADDR);
|
||||
memset(&sAddr, 0, sAddrLen);
|
||||
AZ::s32 result = HandleSocketError(getsockname(sock, &sAddr, &sAddrLen));
|
||||
addr = sAddr;
|
||||
return result;
|
||||
}
|
||||
|
||||
AZ::s32 Connect(AZSOCKET sock, const AzSocketAddress& addr)
|
||||
{
|
||||
AZ::s32 err = HandleSocketError(connect(sock, addr.GetTargetAddress(), sizeof(AZSOCKADDR_IN)));
|
||||
if (err == static_cast<AZ::s32>(AzSockError::eASE_EINPROGRESS))
|
||||
{
|
||||
err = static_cast<AZ::s32>(AzSockError::eASE_EWOULDBLOCK_CONN);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
AZ::s32 Listen(AZSOCKET sock, AZ::s32 backlog)
|
||||
{
|
||||
return HandleSocketError(listen(sock, backlog));
|
||||
}
|
||||
|
||||
AZSOCKET Accept(AZSOCKET sock, AzSocketAddress& addr)
|
||||
{
|
||||
AZSOCKADDR sAddr;
|
||||
AZSOCKLEN sAddrLen = sizeof(AZSOCKADDR);
|
||||
memset(&sAddr, 0, sAddrLen);
|
||||
AZSOCKET outSock = HandleInvalidSocket(accept(sock, &sAddr, &sAddrLen));
|
||||
addr = sAddr;
|
||||
return outSock;
|
||||
}
|
||||
|
||||
AZ::s32 Send(AZSOCKET sock, const char* buf, AZ::s32 len, AZ::s32 flags)
|
||||
{
|
||||
AZ::s32 msgNoSignal = MSG_NOSIGNAL;
|
||||
return HandleSocketError(send(sock, buf, len, flags | msgNoSignal));
|
||||
}
|
||||
|
||||
AZ::s32 Recv(AZSOCKET sock, char* buf, AZ::s32 len, AZ::s32 flags)
|
||||
{
|
||||
return HandleSocketError(recv(sock, buf, len, flags));
|
||||
}
|
||||
|
||||
AZ::s32 Bind(AZSOCKET sock, const AzSocketAddress& addr)
|
||||
{
|
||||
return HandleSocketError(bind(sock, addr.GetTargetAddress(), sizeof(AZSOCKADDR_IN)));
|
||||
}
|
||||
|
||||
AZ::s32 Select(AZSOCKET sock, AZFD_SET* readfdsock, AZFD_SET* writefdsock, AZFD_SET* exceptfdsock, AZTIMEVAL* timeout)
|
||||
{
|
||||
return HandleSocketError(::select(sock + 1, readfdsock, writefdsock, exceptfdsock, timeout));
|
||||
}
|
||||
|
||||
AZ::s32 IsRecvPending(AZSOCKET sock, AZTIMEVAL* timeout)
|
||||
{
|
||||
AZFD_SET readSet;
|
||||
FD_ZERO(&readSet);
|
||||
FD_SET(sock, &readSet);
|
||||
|
||||
AZ::s32 ret = Select(sock, &readSet, nullptr, nullptr, timeout);
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = FD_ISSET(sock, &readSet);
|
||||
if (ret != 0)
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
AZ::s32 WaitForWritableSocket(AZSOCKET sock, AZTIMEVAL* timeout)
|
||||
{
|
||||
AZFD_SET writeSet;
|
||||
FD_ZERO(&writeSet);
|
||||
FD_SET(sock, &writeSet);
|
||||
|
||||
AZ::s32 ret = Select(sock, nullptr, &writeSet, nullptr, timeout);
|
||||
if (ret >= 0)
|
||||
{
|
||||
ret = FD_ISSET(sock, &writeSet);
|
||||
if (ret != 0)
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
AZ::s32 Startup()
|
||||
{
|
||||
return static_cast<AZ::s32>(AzSockError::eASE_NO_ERROR);
|
||||
}
|
||||
|
||||
AZ::s32 Cleanup()
|
||||
{
|
||||
return static_cast<AZ::s32>(AzSockError::eASE_NO_ERROR);
|
||||
}
|
||||
|
||||
bool ResolveAddress(const AZStd::string& ip, AZ::u16 port, AZSOCKADDR_IN& socketAddress)
|
||||
{
|
||||
bool foundAddr = false;
|
||||
addrinfo hints;
|
||||
memset(&hints, 0, sizeof(addrinfo));
|
||||
addrinfo* addrInfo;
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
char strPort[8];
|
||||
azsnprintf(strPort, AZ_ARRAY_SIZE(strPort), "%d", port);
|
||||
|
||||
const char* address = ip.c_str();
|
||||
if (address && strlen(address) == 0) // getaddrinfo doesn't accept empty string
|
||||
{
|
||||
address = nullptr;
|
||||
}
|
||||
|
||||
AZ::s32 err = HandleSocketError(getaddrinfo(address, strPort, &hints, &addrInfo));
|
||||
if (err == 0) // eASE_NO_ERROR
|
||||
{
|
||||
if (addrInfo->ai_family == AF_INET)
|
||||
{
|
||||
socketAddress = *reinterpret_cast<const AZSOCKADDR_IN*>(addrInfo->ai_addr);
|
||||
foundAddr = true;
|
||||
}
|
||||
|
||||
freeaddrinfo(addrInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Assert(false, "AzSocketAddress could not resolve address %s with port %d. (reason - %s)", ip.c_str(), port, GetStringForError(err));
|
||||
}
|
||||
return foundAddr;
|
||||
}
|
||||
} // namespace AZ::AzSock
|
||||
|
||||
@@ -11,68 +11,65 @@
|
||||
#include <cstdlib>
|
||||
#include <pwd.h>
|
||||
|
||||
namespace AZ
|
||||
namespace AZ::Utils
|
||||
{
|
||||
namespace Utils
|
||||
void RequestAbnormalTermination()
|
||||
{
|
||||
void RequestAbnormalTermination()
|
||||
abort();
|
||||
}
|
||||
|
||||
void NativeErrorMessageBox(const char*, const char*) {}
|
||||
|
||||
AZ::IO::FixedMaxPathString GetHomeDirectory()
|
||||
{
|
||||
constexpr AZStd::string_view overrideHomeDirKey = "/Amazon/Settings/override_home_dir";
|
||||
AZ::IO::FixedMaxPathString overrideHomeDir;
|
||||
if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
|
||||
void NativeErrorMessageBox(const char*, const char*) {}
|
||||
|
||||
AZ::IO::FixedMaxPathString GetHomeDirectory()
|
||||
{
|
||||
constexpr AZStd::string_view overrideHomeDirKey = "/Amazon/Settings/override_home_dir";
|
||||
AZ::IO::FixedMaxPathString overrideHomeDir;
|
||||
if (auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
|
||||
if (settingsRegistry->Get(overrideHomeDir, overrideHomeDirKey))
|
||||
{
|
||||
if (settingsRegistry->Get(overrideHomeDir, overrideHomeDirKey))
|
||||
{
|
||||
AZ::IO::FixedMaxPath path{overrideHomeDir};
|
||||
return path.Native();
|
||||
}
|
||||
}
|
||||
|
||||
if (const char* homePath = std::getenv("HOME"); homePath != nullptr)
|
||||
{
|
||||
AZ::IO::FixedMaxPath path{homePath};
|
||||
AZ::IO::FixedMaxPath path{overrideHomeDir};
|
||||
return path.Native();
|
||||
}
|
||||
|
||||
struct passwd* pass = getpwuid(getuid());
|
||||
if (pass)
|
||||
{
|
||||
AZ::IO::FixedMaxPath path{pass->pw_dir};
|
||||
return path.Native();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool ConvertToAbsolutePath(const char* path, char* absolutePath, AZ::u64 maxLength)
|
||||
if (const char* homePath = std::getenv("HOME"); homePath != nullptr)
|
||||
{
|
||||
AZ::IO::FixedMaxPath path{homePath};
|
||||
return path.Native();
|
||||
}
|
||||
|
||||
struct passwd* pass = getpwuid(getuid());
|
||||
if (pass)
|
||||
{
|
||||
AZ::IO::FixedMaxPath path{pass->pw_dir};
|
||||
return path.Native();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool ConvertToAbsolutePath(const char* path, char* absolutePath, AZ::u64 maxLength)
|
||||
{
|
||||
#ifdef PATH_MAX
|
||||
static constexpr size_t UnixMaxPathLength = PATH_MAX;
|
||||
static constexpr size_t UnixMaxPathLength = PATH_MAX;
|
||||
#else
|
||||
// Fallback to 4096 if the PATH_MAX macro isn't defined on the Unix System
|
||||
static constexpr size_t UnixMaxPathLength = 4096;
|
||||
// Fallback to 4096 if the PATH_MAX macro isn't defined on the Unix System
|
||||
static constexpr size_t UnixMaxPathLength = 4096;
|
||||
#endif
|
||||
if (!AZ::IO::PathView(path).IsAbsolute())
|
||||
if (!AZ::IO::PathView(path).IsAbsolute())
|
||||
{
|
||||
// note that realpath fails if the path does not exist and actually changes the return value
|
||||
// to be the actual place that FAILED, which we don't want.
|
||||
// if we fail, we'd prefer to fall through and at least use the original path.
|
||||
char absolutePathBuffer[UnixMaxPathLength];
|
||||
if (const char* result = realpath(path, absolutePathBuffer); result != nullptr)
|
||||
{
|
||||
// note that realpath fails if the path does not exist and actually changes the return value
|
||||
// to be the actual place that FAILED, which we don't want.
|
||||
// if we fail, we'd prefer to fall through and at least use the original path.
|
||||
char absolutePathBuffer[UnixMaxPathLength];
|
||||
if (const char* result = realpath(path, absolutePathBuffer); result != nullptr)
|
||||
{
|
||||
azstrcpy(absolutePath, maxLength, absolutePathBuffer);
|
||||
return true;
|
||||
}
|
||||
azstrcpy(absolutePath, maxLength, absolutePathBuffer);
|
||||
return true;
|
||||
}
|
||||
azstrcpy(absolutePath, maxLength, path);
|
||||
return AZ::IO::PathView(absolutePath).IsAbsolute();
|
||||
}
|
||||
} // namespace Utils
|
||||
} // namespace AZ
|
||||
azstrcpy(absolutePath, maxLength, path);
|
||||
return AZ::IO::PathView(absolutePath).IsAbsolute();
|
||||
}
|
||||
} // namespace AZ::Utils
|
||||
|
||||
@@ -9,16 +9,10 @@
|
||||
#include <AzCore/Debug/Trace.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace AZ
|
||||
namespace AZ::Debug::Platform
|
||||
{
|
||||
namespace Debug
|
||||
void OutputToDebugger([[maybe_unused]] const char* title, [[maybe_unused]] const char* message)
|
||||
{
|
||||
namespace Platform
|
||||
{
|
||||
void OutputToDebugger([[maybe_unused]] const char* title, [[maybe_unused]] const char* message)
|
||||
{
|
||||
// std::cout << title << ": " << message;
|
||||
}
|
||||
}
|
||||
// std::cout << title << ": " << message;
|
||||
}
|
||||
}
|
||||
} // namespace AZ::Debug::Platform
|
||||
|
||||
@@ -8,13 +8,10 @@
|
||||
|
||||
#include <AzCore/base.h>
|
||||
|
||||
namespace AZ
|
||||
namespace AZ::Platform
|
||||
{
|
||||
namespace Platform
|
||||
size_t GetHeapCapacity()
|
||||
{
|
||||
size_t GetHeapCapacity()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} // namespace AZ::Platform
|
||||
|
||||
@@ -10,28 +10,25 @@
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
namespace AZ
|
||||
namespace AZ::Platform
|
||||
{
|
||||
namespace Platform
|
||||
AZ::IO::FixedMaxPath GetModulePath()
|
||||
{
|
||||
AZ::IO::FixedMaxPath GetModulePath()
|
||||
{
|
||||
return AZ::Utils::GetExecutableDirectory();
|
||||
}
|
||||
|
||||
void* OpenModule(const AZ::OSString& fileName, bool& alreadyOpen)
|
||||
{
|
||||
void* handle = dlopen(fileName.c_str(), RTLD_NOLOAD);
|
||||
alreadyOpen = (handle != nullptr);
|
||||
if (!alreadyOpen)
|
||||
{
|
||||
handle = dlopen(fileName.c_str(), RTLD_NOW);
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
void ConstructModuleFullFileName(AZ::IO::FixedMaxPath&)
|
||||
{
|
||||
}
|
||||
return AZ::Utils::GetExecutableDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
void* OpenModule(const AZ::OSString& fileName, bool& alreadyOpen)
|
||||
{
|
||||
void* handle = dlopen(fileName.c_str(), RTLD_NOLOAD);
|
||||
alreadyOpen = (handle != nullptr);
|
||||
if (!alreadyOpen)
|
||||
{
|
||||
handle = dlopen(fileName.c_str(), RTLD_NOW);
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
void ConstructModuleFullFileName(AZ::IO::FixedMaxPath&)
|
||||
{
|
||||
}
|
||||
} // namespace AZ::Platform
|
||||
|
||||
+10
-13
@@ -8,20 +8,17 @@
|
||||
|
||||
#include <AzCore/Module/Internal/ModuleManagerSearchPathTool.h>
|
||||
|
||||
namespace AZ
|
||||
namespace AZ::Internal
|
||||
{
|
||||
namespace Internal
|
||||
ModuleManagerSearchPathTool::ModuleManagerSearchPathTool()
|
||||
{
|
||||
ModuleManagerSearchPathTool::ModuleManagerSearchPathTool()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
ModuleManagerSearchPathTool::~ModuleManagerSearchPathTool()
|
||||
{
|
||||
}
|
||||
ModuleManagerSearchPathTool::~ModuleManagerSearchPathTool()
|
||||
{
|
||||
}
|
||||
|
||||
void ModuleManagerSearchPathTool::SetModuleSearchPath(const AZ::DynamicModuleDescriptor&)
|
||||
{
|
||||
}
|
||||
} // namespace Internal
|
||||
} // namespace AZ
|
||||
void ModuleManagerSearchPathTool::SetModuleSearchPath(const AZ::DynamicModuleDescriptor&)
|
||||
{
|
||||
}
|
||||
} // namespace AZ::Internal
|
||||
|
||||
@@ -13,42 +13,39 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
namespace AZ
|
||||
namespace AZ::Utils
|
||||
{
|
||||
namespace Utils
|
||||
GetExecutablePathReturnType GetExecutablePath(char* exeStorageBuffer, size_t exeStorageSize)
|
||||
{
|
||||
GetExecutablePathReturnType GetExecutablePath(char* exeStorageBuffer, size_t exeStorageSize)
|
||||
GetExecutablePathReturnType result;
|
||||
result.m_pathIncludesFilename = true;
|
||||
|
||||
// http://man7.org/linux/man-pages/man5/proc.5.html
|
||||
const ssize_t bytesWritten = readlink("/proc/self/exe", exeStorageBuffer, exeStorageSize);
|
||||
if (bytesWritten == -1)
|
||||
{
|
||||
GetExecutablePathReturnType result;
|
||||
result.m_pathIncludesFilename = true;
|
||||
|
||||
// http://man7.org/linux/man-pages/man5/proc.5.html
|
||||
const ssize_t bytesWritten = readlink("/proc/self/exe", exeStorageBuffer, exeStorageSize);
|
||||
if (bytesWritten == -1)
|
||||
{
|
||||
result.m_pathStored = ExecutablePathResult::GeneralError;
|
||||
}
|
||||
else if (bytesWritten == exeStorageSize)
|
||||
{
|
||||
result.m_pathStored = ExecutablePathResult::BufferSizeNotLargeEnough;
|
||||
}
|
||||
else
|
||||
{
|
||||
// readlink doesn't null terminate
|
||||
exeStorageBuffer[bytesWritten] = '\0';
|
||||
}
|
||||
|
||||
return result;
|
||||
result.m_pathStored = ExecutablePathResult::GeneralError;
|
||||
}
|
||||
else if (bytesWritten == exeStorageSize)
|
||||
{
|
||||
result.m_pathStored = ExecutablePathResult::BufferSizeNotLargeEnough;
|
||||
}
|
||||
else
|
||||
{
|
||||
// readlink doesn't null terminate
|
||||
exeStorageBuffer[bytesWritten] = '\0';
|
||||
}
|
||||
|
||||
AZStd::optional<AZ::IO::FixedMaxPathString> GetDefaultAppRootPath()
|
||||
{
|
||||
return AZStd::nullopt;
|
||||
}
|
||||
|
||||
AZStd::optional<AZ::IO::FixedMaxPathString> GetDevWriteStoragePath()
|
||||
{
|
||||
return AZStd::nullopt;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
AZStd::optional<AZ::IO::FixedMaxPathString> GetDefaultAppRootPath()
|
||||
{
|
||||
return AZStd::nullopt;
|
||||
}
|
||||
|
||||
AZStd::optional<AZ::IO::FixedMaxPathString> GetDevWriteStoragePath()
|
||||
{
|
||||
return AZStd::nullopt;
|
||||
}
|
||||
} // namespace AZ::Utils
|
||||
|
||||
Reference in New Issue
Block a user