Fixed the Logging system to actually be able to handle errors. Database is also fixed to use directories.
This commit is contained in:
@@ -17,15 +17,15 @@ namespace ehs
|
||||
{
|
||||
code = shutdown(hdl, SD_SEND);
|
||||
if (code == SOCKET_ERROR)
|
||||
EHS_LOG_INT("Error", 0, "Failed to shutdown socket with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to shutdown socket with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
}
|
||||
|
||||
code = closesocket(hdl);
|
||||
if (code == SOCKET_ERROR)
|
||||
EHS_LOG_INT("Error", 1, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
|
||||
if (!connection && 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()) + ".");
|
||||
}
|
||||
|
||||
TCP::TCP()
|
||||
@@ -86,7 +86,7 @@ namespace ehs
|
||||
int code = WSAStartup(MAKEWORD(2, 2), &data);
|
||||
if (code)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "WSAStartup failed with the error #" + Str_8::FromNum(code) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "WSAStartup failed with the error #" + Str_8::FromNum(code) + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -101,10 +101,10 @@ namespace ehs
|
||||
{
|
||||
UInt_32 code = WSAGetLastError();
|
||||
|
||||
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 (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()) + ".");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,17 +119,17 @@ namespace ehs
|
||||
{
|
||||
code = shutdown(hdl, SD_SEND);
|
||||
if (code == SOCKET_ERROR)
|
||||
EHS_LOG_INT("Error", 0, "Failed to shutdown socket with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to shutdown socket with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
}
|
||||
|
||||
code = closesocket(hdl);
|
||||
if (code == SOCKET_ERROR)
|
||||
EHS_LOG_INT("Error", 1, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to close socket with error #" + Str_8::FromNum(GetLastError()) + ".");
|
||||
|
||||
hdl = EHS_INVALID_SOCKET;
|
||||
|
||||
if (!connection && 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()) + ".");
|
||||
|
||||
connection = false;
|
||||
bound = false;
|
||||
@@ -161,7 +161,7 @@ namespace ehs
|
||||
int code = listen(hdl, SOMAXCONN);
|
||||
if (code == -1)
|
||||
{
|
||||
EHS_LOG_INT("Error", 0, "Failed to listen with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to listen with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ namespace ehs
|
||||
Int_32 code = WSAGetLastError();
|
||||
|
||||
if (code != WSAEWOULDBLOCK)
|
||||
EHS_LOG_INT("Error", 0, "Failed to accept client with error #" + Str_8::FromNum(code) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 0, "Failed to accept client with error #" + Str_8::FromNum(code) + ".");
|
||||
|
||||
delete client;
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace ehs
|
||||
{
|
||||
Int_32 code = WSAGetLastError();
|
||||
|
||||
EHS_LOG_INT("Error", 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(code) + ".");
|
||||
|
||||
delete client;
|
||||
|
||||
@@ -222,7 +222,7 @@ namespace ehs
|
||||
{
|
||||
Int_32 code = WSAGetLastError();
|
||||
|
||||
EHS_LOG_INT("Error", 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(code) + ".");
|
||||
|
||||
delete client;
|
||||
|
||||
@@ -257,13 +257,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;
|
||||
}
|
||||
|
||||
@@ -274,10 +274,10 @@ namespace ehs
|
||||
if (err == WSAECONNRESET)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -289,13 +289,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;
|
||||
}
|
||||
|
||||
@@ -306,15 +306,15 @@ namespace ehs
|
||||
if (err == WSAECONNRESET)
|
||||
{
|
||||
Release();
|
||||
EHS_LOG_INT("Information", 0, "Connection dropped.");
|
||||
EHS_LOG_INT(LogType::INFO, 0, "Connection dropped.");
|
||||
}
|
||||
else if (err == WSAECONNABORTED)
|
||||
{
|
||||
EHS_LOG_INT("Information", 1, "Receiving timed-out.");
|
||||
EHS_LOG_INT(LogType::INFO, 1, "Receiving timed-out.");
|
||||
}
|
||||
else if (err != WSAEWOULDBLOCK)
|
||||
{
|
||||
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;
|
||||
@@ -327,7 +327,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -335,14 +335,14 @@ namespace ehs
|
||||
|
||||
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) + ".");
|
||||
}
|
||||
|
||||
bool TCP::IsBlocking() const
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -363,14 +363,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 = WSAGetLastError();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -382,7 +382,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(WSAGetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -399,14 +399,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 = WSAGetLastError();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -418,7 +418,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(WSAGetLastError()) + ".");
|
||||
EHS_LOG_INT(LogType::ERR, 2, "Failed to bind socket with error #" + Str_8::FromNum(WSAGetLastError()) + ".");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -433,14 +433,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 = WSAGetLastError();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -450,11 +450,11 @@ namespace ehs
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAETIMEDOUT)
|
||||
{
|
||||
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;
|
||||
@@ -470,14 +470,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 = WSAGetLastError();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -487,11 +487,11 @@ namespace ehs
|
||||
int err = WSAGetLastError();
|
||||
if (err == WSAETIMEDOUT)
|
||||
{
|
||||
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;
|
||||
|
Reference in New Issue
Block a user