Added error handling for receiving case and also when the socket has been closed
This commit is contained in:
parent
d2d140b354
commit
543a6168ed
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -2,9 +2,9 @@ module base.types;
|
|||
|
||||
public class BesterException : Exception
|
||||
{
|
||||
this()
|
||||
this(string message)
|
||||
{
|
||||
/* TODO: Implement me */
|
||||
super("");
|
||||
/* TODO: Implement me */
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -202,6 +202,6 @@ public final class ResponseError : BesterException
|
|||
this(JSONValue messageResponse, ulong statusCode)
|
||||
{
|
||||
/* TODO: Set message afterwards again */
|
||||
super();
|
||||
super("");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue