diff --git a/source/base/net.d b/source/base/net.d new file mode 100644 index 0000000..08b7420 --- /dev/null +++ b/source/base/net.d @@ -0,0 +1,12 @@ +module base.net; + +import base.types; +import std.socket : Socket; + +public class NetworkException : BesterException +{ + this(Socket socketResponsible) + { + super("Socket error with: " ~ socketResponsible.remoteAddress().toAddrString()); + } +} \ No newline at end of file diff --git a/source/base/types.d b/source/base/types.d index 759ef80..7b1d8d0 100644 --- a/source/base/types.d +++ b/source/base/types.d @@ -2,9 +2,9 @@ module base.types; public class BesterException : Exception { - this() + this(string message) { - /* TODO: Implement me */ - super(""); + /* TODO: Implement me */ + super(message); } } \ No newline at end of file diff --git a/source/connection/connection.d b/source/connection/connection.d index 63125ec..ffd4f6a 100644 --- a/source/connection/connection.d +++ b/source/connection/connection.d @@ -12,6 +12,7 @@ import listeners.listener; import server.server; import handlers.response; import connection.message; +import base.net; public final class BesterConnection : Thread { @@ -85,12 +86,19 @@ public final class BesterConnection : Thread /** * If the message was received successfully then * process the message. */ - processMessage(receivedMessage); + processMessage(receivedMessage); + + /* TODO: Check socket status here, the client might have issued a command to close the connection */ + if(!clientConnection.isAlive()) + { + debugPrint("Socket is dead."); + break; + } } else { debugPrint("[ReadSendLoop] Error with receiving from socket, ending..."); - break; + throw new NetworkException(clientConnection); } } debugPrint("<<< End read/send loop >>>"); @@ -115,6 +123,11 @@ public final class BesterConnection : Thread bool receiveStatus = receiveMessage(handlerSocket, response); /* TODO: Use `receiveStatus` */ + if(!receiveStatus) + { + /* TODO: Add throw here */ + throw new NetworkException(handlerSocket); + } return response; } diff --git a/source/handlers/response.d b/source/handlers/response.d index fccb54e..bda9836 100644 --- a/source/handlers/response.d +++ b/source/handlers/response.d @@ -202,6 +202,6 @@ public final class ResponseError : BesterException this(JSONValue messageResponse, ulong statusCode) { /* TODO: Set message afterwards again */ - super(); + super(""); } } \ No newline at end of file