Fixed the Logging system to actually be able to handle errors. Database is also fixed to use directories.

This commit is contained in:
2024-04-23 22:29:49 -07:00
parent 2734cc00fb
commit f030ac62ae
61 changed files with 884 additions and 602 deletions

View File

@@ -108,7 +108,7 @@ namespace ehc
int wsaCode = WSAStartup(MAKEWORD(2, 2), &data);
if (wsaCode)
{
EHS_LOG_INT("Error", 0, "WSAStartup failed with the error #" + Str_8::FromNum(wsaCode) + ".");
EHS_LOG_INT(LogType::ERR, 0, "WSAStartup failed with the error #" + Str_8::FromNum(wsaCode) + ".");
return;
}
#endif
@@ -130,11 +130,11 @@ namespace ehc
code = errno;
#endif
EHS_LOG_INT("Error", 1, "Failed to create socket with error #" + Str_8::FromNum(code) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to create socket with error #" + Str_8::FromNum(code) + ".");
#if defined(EHS_OS_WINDOWS)
if (WSACleanup() == SOCKET_ERROR)
EHS_LOG_INT("Error", 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
EHS_LOG_INT(LogType::ERR, 2, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
#endif
return;
@@ -182,18 +182,18 @@ namespace ehc
#if defined(EHS_OS_WINDOWS)
code = closesocket(hdl);
if (code == SOCKET_ERROR)
EHS_LOG_INT("Error", 0, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
#elif defined(EHS_OS_LINUX)
code = close(hdl);
if (code == -1)
EHS_LOG_INT("Error", 0, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
#endif
hdl = EHS_INVALID_SOCKET;
#if defined(EHS_OS_WINDOWS)
if (WSACleanup() == SOCKET_ERROR)
EHS_LOG_INT("Error", 1, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to shutdown WSA with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
#endif
bound = false;
@@ -246,7 +246,7 @@ namespace ehc
if (msg.Size())
dcMsg += " Reason: " + msg;
EHS_LOG_INT("Info", 0, dcMsg);
EHS_LOG_INT(LogType::INFO, 0, dcMsg);
Serializer<> payload(Endianness::LE);
payload.WriteStr(msg);
@@ -389,7 +389,7 @@ namespace ehc
sPayload.Write(Status::IN_REMOTE_QUEUE);
sPayload.Write(end->GetQueueSlot());
EHS_LOG_INT("Info", 1, end->GetId() + " connected and is in queue slot " + end->GetQueueSlot() + ".");
EHS_LOG_INT(LogType::INFO, 1, end->GetId() + " connected and is in queue slot " + end->GetQueueSlot() + ".");
}
else
{
@@ -401,7 +401,7 @@ namespace ehc
sPayload.Write(Status::ACTIVE);
sPayload.Write(0);
EHS_LOG_INT("Info", 1, end->GetId() + " connected.");
EHS_LOG_INT(LogType::INFO, 1, end->GetId() + " connected.");
}
end->Send(false, true, false, internalSys, connectedOp, sPayload);
@@ -429,7 +429,7 @@ namespace ehc
else
msg += ".";
EHS_LOG_INT("Info", 2, msg);
EHS_LOG_INT(LogType::INFO, 2, msg);
}
else if (!header.ensure && header.endpointId && header.system == internalSys && header.op == rejectedOp)
{
@@ -438,7 +438,7 @@ namespace ehc
Str_8 msg = payload.ReadStr<Char_8, UInt_64>();
if (msg.Size())
EHS_LOG_INT("Info", 3, msg);
EHS_LOG_INT(LogType::INFO, 3, msg);
}
else if (!header.ensure && header.endpointId && header.system == internalSys && header.op == disconnectOp)
{
@@ -462,7 +462,7 @@ namespace ehc
if (msg.Size())
dcMsg += " Reason: " + msg;
EHS_LOG_INT("Info", 4, dcMsg);
EHS_LOG_INT(LogType::INFO, 4, dcMsg);
RemoveEndpoint(header.disposition, end->GetHashId());
@@ -493,11 +493,11 @@ namespace ehc
if (activeCb)
activeCb(this, end);
EHS_LOG_INT("Info", 5, "Your connection status to " + end->GetId() + " has now become active.");
EHS_LOG_INT(LogType::INFO, 5, "Your connection status to " + end->GetId() + " has now become active.");
}
else if (end->GetStatus() == Status::IN_REMOTE_QUEUE && newStatus == Status::IN_REMOTE_QUEUE)
{
EHS_LOG_INT("Info", 5, "Your queue slot for " + end->GetId() + " is now " + newSlot + ".");
EHS_LOG_INT(LogType::INFO, 5, "Your queue slot for " + end->GetId() + " is now " + newSlot + ".");
}
end->SetStatus(newStatus);
@@ -548,7 +548,7 @@ namespace ehc
if (dropPackets && !header.ensure && header.id < end->GetNextRecvId())
{
EHS_LOG_INT("Info", 6, "Old packet intentionally dropped.");
EHS_LOG_INT(LogType::INFO, 6, "Old packet intentionally dropped.");
continue;
}
@@ -568,7 +568,7 @@ namespace ehc
}
else
{
EHS_LOG_INT("Info", 7, "Corrupted packet.");
EHS_LOG_INT(LogType::INFO, 7, "Corrupted packet.");
}
}
@@ -853,7 +853,7 @@ namespace ehc
{
if (hdl == EHS_INVALID_SOCKET)
{
EHS_LOG_INT("Error", 0, "Attempted to toggle blocking while socket is not initialized.");
EHS_LOG_INT(LogType::ERR, 0, "Attempted to toggle blocking while socket is not initialized.");
return;
}
@@ -862,10 +862,10 @@ namespace ehc
int result = ioctlsocket(hdl, FIONBIO, &r);
if (result != NO_ERROR)
EHS_LOG_INT("Error", 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(result) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(result) + ".");
#elif defined(EHS_OS_LINUX)
if (fcntl(hdl, F_SETFL, O_NONBLOCK, blocking) == -1)
EHS_LOG_INT("Error", 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to toggle non-blocking mode with error #" + Str_8::FromNum(errno) + ".");
#endif
}
@@ -874,7 +874,7 @@ namespace ehc
#if defined(EHS_OS_WINDOWS)
u_long r = 0;
if (ioctlsocket(hdl, FIONREAD, &r) == SOCKET_ERROR)
EHS_LOG_INT("Error", 0, "Failed to retrieve socket info.");
EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve socket info.");
return (bool)r;
#elif defined(EHS_OS_LINUX)
@@ -1043,7 +1043,7 @@ namespace ehc
{
if (endpoints[i]->GetTimeout() >= maxTimeout)
{
EHS_LOG_INT("Info", 0, "Failed to connect to, \"" + endpoints[i]->GetAddress() + ":" + Str_8::FromNum(endpoints[i]->GetPort()) + "\".");
EHS_LOG_INT(LogType::INFO, 0, "Failed to connect to, \"" + endpoints[i]->GetAddress() + ":" + Str_8::FromNum(endpoints[i]->GetPort()) + "\".");
delete endpoints[i];
@@ -1059,7 +1059,7 @@ namespace ehc
{
if (endpoints[i]->GetTimeout() >= maxTimeout)
{
EHS_LOG_INT("Info", 6, endpoints[i]->GetId() + " timed out.");
EHS_LOG_INT(LogType::INFO, 6, endpoints[i]->GetId() + " timed out.");
if (disconnectedCb)
disconnectedCb(this, endpoints[i]);
@@ -1120,7 +1120,7 @@ namespace ehc
Int_32 code = inet_pton(AF_INET6, address, &result.sin6_addr);
if (!code)
{
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid.");
EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return;
}
else if (code == -1)
@@ -1133,7 +1133,7 @@ namespace ehc
dCode = errno;
#endif
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return;
}
}
@@ -1147,13 +1147,13 @@ namespace ehc
#if defined(EHS_OS_WINDOWS)
if (code == SOCKET_ERROR)
{
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return;
}
#elif defined(EHS_OS_LINUX)
if (code == -1)
{
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + ".");
return;
}
#endif
@@ -1172,7 +1172,7 @@ namespace ehc
code = inet_pton(AF_INET, address, &result.sin_addr);
if (!code)
{
EHS_LOG_INT("Error", 0, "The given address, \"" + address + "\" is not valid.");
EHS_LOG_INT(LogType::ERR, 0, "The given address, \"" + address + "\" is not valid.");
return;
}
else if (code == -1)
@@ -1185,7 +1185,7 @@ namespace ehc
dCode = errno;
#endif
EHS_LOG_INT("Error", 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert address with error #" + Str_8::FromNum(dCode) + ".");
return;
}
}
@@ -1199,13 +1199,13 @@ namespace ehc
#if defined(EHS_OS_WINDOWS)
if (code == SOCKET_ERROR)
{
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
return;
}
#elif defined(EHS_OS_LINUX)
if (code == -1)
{
EHS_LOG_INT("Error", 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(errno) + ".");
return;
}
#endif
@@ -1215,13 +1215,13 @@ namespace ehc
{
if (hdl == EHS_INVALID_SOCKET)
{
EHS_LOG_INT("Error", 0, "Attempted to receive while socket is not initialized.");
EHS_LOG_INT(LogType::ERR, 0, "Attempted to receive while socket is not initialized.");
return 0;
}
if (type == AddrType::IPV4 && size > EHS_IPV4_UDP_PAYLOAD)
{
EHS_LOG_INT("Error", 1, "Attempted to receive with a buffer size of, \"" + Str_8::FromNum(size)
EHS_LOG_INT(LogType::ERR, 1, "Attempted to receive with a buffer size of, \"" + Str_8::FromNum(size)
+ "\", that exceeds, \"" + Str_8::FromNum(EHS_IPV4_UDP_PAYLOAD) + ".");
}
@@ -1238,13 +1238,13 @@ namespace ehc
{
UnInitialize();
EHS_LOG_INT("Error", 2, "The buffer size, \"" + Str_8::FromNum(size) + "\" is too small.");
EHS_LOG_INT(LogType::ERR, 2, "The buffer size, \"" + Str_8::FromNum(size) + "\" is too small.");
}
else if (code != WSAECONNRESET && code != WSAEWOULDBLOCK)
{
UnInitialize();
EHS_LOG_INT("Error", 3, "Failed to receive with error #" + Str_8::FromNum(code) + ".");
EHS_LOG_INT(LogType::ERR, 3, "Failed to receive with error #" + Str_8::FromNum(code) + ".");
}
return 0;
@@ -1258,7 +1258,7 @@ namespace ehc
{
UnInitialize();
EHS_LOG_INT("Error", 2, "Failed to receive with error #" + Str_8::FromNum(code) + ".");
EHS_LOG_INT(LogType::ERR, 2, "Failed to receive with error #" + Str_8::FromNum(code) + ".");
}
return 0;
@@ -1280,7 +1280,7 @@ namespace ehc
code = errno;
#endif
EHS_LOG_INT("Error", 2, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + ".");
EHS_LOG_INT(LogType::ERR, 2, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + ".");
return received;
}
@@ -1302,7 +1302,7 @@ namespace ehc
code = errno;
#endif
EHS_LOG_INT("Error", 2, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + ".");
EHS_LOG_INT(LogType::ERR, 2, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + ".");
return (UInt_16)received;
}