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

@@ -18,11 +18,11 @@ namespace ehs
if (connection)
{
if (shutdown(hdl, SHUT_RDWR) == -1)
EHS_LOG_INT("Error", 0, "Failed to shutdown socket with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 0, "Failed to shutdown socket with error #" + Str_8::FromNum(errno) + ".");
}
if (close(hdl) == -1)
EHS_LOG_INT("Error", 1, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
}
TCP::TCP()
@@ -89,7 +89,7 @@ namespace ehs
{
UInt_32 code = errno;
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) + ".");
}
}
@@ -101,11 +101,11 @@ namespace ehs
if (connection)
{
if (shutdown(hdl, SHUT_RDWR) == -1)
EHS_LOG_INT("Error", 0, "Failed to shutdown socket with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 0, "Failed to shutdown socket with error #" + Str_8::FromNum(errno) + ".");
}
if (close(hdl) == -1)
EHS_LOG_INT("Error", 1, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to close socket with error #" + Str_8::FromNum(errno) + ".");
connection = false;
bound = false;
@@ -138,7 +138,7 @@ namespace ehs
int code = listen(hdl, SOMAXCONN);
if (code == -1)
{
EHS_LOG_INT("Error", 0, "Failed to listen with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 0, "Failed to listen with error #" + Str_8::FromNum(errno) + ".");
return;
}
@@ -164,7 +164,7 @@ namespace ehs
if (client->hdl == EHS_INVALID_SOCKET)
{
if (errno != EWOULDBLOCK)
EHS_LOG_INT("Error", 0, "Failed to accept client with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 0, "Failed to accept client with error #" + Str_8::FromNum(errno) + ".");
delete client;
@@ -177,7 +177,7 @@ namespace ehs
if (!inet_ntop(remote.sin6_family, &remote.sin6_addr, tmpAddr, INET6_ADDRSTRLEN))
{
EHS_LOG_INT("Error", 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(errno) + ".");
delete client;
@@ -193,7 +193,7 @@ namespace ehs
if (!inet_ntop(((sockaddr_in*)&remote)->sin_family, &((sockaddr_in*)&remote)->sin_addr, tmpAddr, INET_ADDRSTRLEN))
{
EHS_LOG_INT("Error", 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(errno) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(errno) + ".");
delete client;
@@ -228,13 +228,13 @@ namespace ehs
{
if (!IsValid())
{
EHS_LOG_INT("Error", 0, "Attempted to send while socket is not initialized.");
EHS_LOG_INT(LogType::ERR, 0, "Attempted to send while socket is not initialized.");
return 0;
}
if ((!connection && !connected))
{
EHS_LOG_INT("Error", 1, "Attempted to send while socket is not connected or a connection.");
EHS_LOG_INT(LogType::ERR, 1, "Attempted to send while socket is not connected or a connection.");
return 0;
}
@@ -245,10 +245,10 @@ namespace ehs
if (err == ECONNRESET)
{
Release();
EHS_LOG_INT("Information", 0, "Connection dropped.");
EHS_LOG_INT(LogType::INFO, 0, "Connection dropped.");
}
else
EHS_LOG_INT("Error", 1, "Failed to send with error #" + Str_8::FromNum(err) + ".");
EHS_LOG_INT(LogType::ERR, 1, "Failed to send with error #" + Str_8::FromNum(err) + ".");
return 0;
}
@@ -260,13 +260,13 @@ namespace ehs
{
if (!IsValid())
{
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 ((!connection && !connected))
{
EHS_LOG_INT("Error", 1, "Attempted to receive while socket is not connected or a connection.");
EHS_LOG_INT(LogType::ERR, 1, "Attempted to receive while socket is not connected or a connection.");
return 0;
}
@@ -277,11 +277,11 @@ namespace ehs
if (err == ECONNRESET)
{
Release();
EHS_LOG_INT("Information", 0, "Connection dropped.");
EHS_LOG_INT(LogType::INFO, 0, "Connection dropped.");
}
else if (err != EWOULDBLOCK)
{
EHS_LOG_INT("Error", 2, "Failed to receive with error #" + Str_8::FromNum(err) + ".");
EHS_LOG_INT(LogType::ERR, 2, "Failed to receive with error #" + Str_8::FromNum(err) + ".");
}
return 0;
@@ -294,14 +294,14 @@ namespace ehs
{
if (!IsValid())
{
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;
}
int flags = fcntl(hdl, F_GETFL, 0);
if (flags == -1)
{
EHS_LOG_INT("Error", 0, "Failed to retrieve flags.");
EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve flags.");
return;
}
@@ -311,7 +311,7 @@ namespace ehs
flags |= O_NONBLOCK;
if (fcntl(hdl, F_SETFL, flags) == -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) + ".");
}
bool TCP::IsBlocking() const
@@ -319,7 +319,7 @@ namespace ehs
int flags = fcntl(hdl, F_GETFL, 0);
if (flags == -1)
{
EHS_LOG_INT("Error", 0, "Failed to retrieve flags.");
EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve flags.");
return true;
}
@@ -342,14 +342,14 @@ namespace ehs
int 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)
{
Int_32 dCode = errno;
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;
}
}
@@ -361,7 +361,7 @@ namespace ehs
int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in6));
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;
}
@@ -378,14 +378,14 @@ namespace ehs
int 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)
{
Int_32 dCode = errno;
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;
}
}
@@ -396,7 +396,7 @@ namespace ehs
int code = bind(hdl, (sockaddr*)&result, sizeof(sockaddr_in));
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;
}
@@ -411,14 +411,14 @@ namespace ehs
int 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)
{
Int_32 dCode = errno;
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;
}
@@ -428,11 +428,11 @@ namespace ehs
int err = errno;
if (err == ETIMEDOUT)
{
EHS_LOG_INT("Information", 2, "Connection attempt timed-out.");
EHS_LOG_INT(LogType::INFO, 2, "Connection attempt timed-out.");
}
else
{
EHS_LOG_INT("Error", 3, "Failed to connect with error #" + Str_8::FromNum(err) + ".");
EHS_LOG_INT(LogType::ERR, 3, "Failed to connect with error #" + Str_8::FromNum(err) + ".");
}
return;
@@ -448,14 +448,14 @@ namespace ehs
int 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)
{
Int_32 dCode = errno;
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;
}
@@ -465,11 +465,11 @@ namespace ehs
int err = errno;
if (err == ETIMEDOUT)
{
EHS_LOG_INT("Information", 2, "Connection attempt timed-out.");
EHS_LOG_INT(LogType::INFO, 2, "Connection attempt timed-out.");
}
else
{
EHS_LOG_INT("Error", 3, "Failed to connect with error #" + Str_8::FromNum(err) + ".");
EHS_LOG_INT(LogType::ERR, 3, "Failed to connect with error #" + Str_8::FromNum(err) + ".");
}
return;