From c69a8469039ab1bc3faeb232f5691980c578f8f4 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sun, 26 Apr 2020 18:31:39 +0200 Subject: [PATCH] Removed unused function --- source/connection/connection.d | 194 --------------------------------- 1 file changed, 194 deletions(-) diff --git a/source/connection/connection.d b/source/connection/connection.d index 4eb7747..df50316 100644 --- a/source/connection/connection.d +++ b/source/connection/connection.d @@ -333,200 +333,6 @@ public final class BesterConnection : Thread } - /* TODO: Pass in type and just payload or what */ - private bool dispatch(string payloadType, JSONValue payload) - { - /* TODO: Implement me */ - debugPrint("Dispatching payload [" ~ payloadType ~ "]"); - debugPrint("Payload: " ~ payload.toPrettyString()); - - /* Status of dispatch */ - bool dispatchStatus = true; - - /* Lookup the payloadType handler */ - MessageHandler chosenHandler; - - for(uint i = 0; i < server.handlers.length; i++) - { - if(cmp(server.handlers[i].getPluginName(), payloadType) == 0) - { - chosenHandler = server.handlers[i]; - break; - } - } - - /* Check if a handler was found */ - if(chosenHandler) - { - /* If a handler for the message type was found */ - - /* TODO: Send and receive data here */ - - /* Handler's UNIX domain socket */ - /* TODO: Change this call here below (also remove startup connection) */ - Socket handlerSocket = chosenHandler.getNewSocket(); - //writeln(handlerSocket == null); - debugPrint("chosenHandler.socketPath: " ~ chosenHandler.socketPath); - - /* Get the payload as a string */ - string payloadString = toJSON(payload); - - - /* Send the payload to the message handler */ - sendMessage(handlerSocket, payload); - - - /* Construct the data to send */ - byte[] sendBuffer; - - /* TODO: Add 4 bytes of payload length encded in little endian */ - int payloadLength = cast(int)payloadString.length; - byte* lengthBytes = cast(byte*)&payloadLength; - sendBuffer ~= *(lengthBytes+0); - sendBuffer ~= *(lengthBytes+1); - sendBuffer ~= *(lengthBytes+2); - sendBuffer ~= *(lengthBytes+3); - - /* Add the string bytes */ - sendBuffer ~= cast(byte[])payloadString; - - /* TODO: Send payload */ - writeln("Send buffer: ", sendBuffer); - - debugPrint("Sending payload over to handler for \"" ~ chosenHandler.getPluginName() ~ "\"."); - handlerSocket.send(sendBuffer); - - - /* TODO: Get response */ - debugPrint("Waiting for response from handler for \"" ~ chosenHandler.getPluginName() ~ "\"."); - - /* Construct a buffer to receive into */ - byte[] receiveBuffer; - - /* The current byte */ - uint currentByte = 0; - - /* The amount of bytes received */ - long bytesReceived; - - /* Loop consume the next 4 bytes */ - while(currentByte < 4) - { - /* Temporary buffer */ - byte[4] tempBuffer; - - /* Read at-most 4 bytes */ - bytesReceived = handlerSocket.receive(tempBuffer); - - /* If there was an error reading from the socket */ - if(!(bytesReceived > 0)) - { - /* TODO: Error handling */ - debugPrint("Error receiving from UNIX domain socket"); - } - /* If there is no error reading from the socket */ - else - { - /* Add the read bytes to the *real* buffer */ - receiveBuffer ~= tempBuffer[0..bytesReceived]; - - /* Increment the byte counter */ - currentByte += bytesReceived; - } - } - - /* Response message length */ - int messageLength = *cast(int*)receiveBuffer.ptr; - writeln("Message length is: ", cast(uint)messageLength); - - /* Response message buffer */ - byte[] fullMessage; - - /* Reset the byte counter */ - currentByte = 0; - - while(currentByte < messageLength) - { - debugPrint("dhjkh"); - - /** - * Receive 20 bytes (at most) at a time and don't dequeue from - * the kernel's TCP stack's buffer. - */ - byte[20] tempBuffer; - bytesReceived = handlerSocket.receive(tempBuffer, SocketFlags.PEEK); - - /* Check for an error whilst receiving */ - if(!(bytesReceived > 0)) - { - /* TODO: Error handling */ - debugPrint("Error whilst receiving from unix domain socket"); - } - else - { - /* TODO: Make sure we only take [0, messageLength) bytes */ - if(cast(uint)bytesReceived+currentByte > messageLength) - { - byte[] remainingBytes; - remainingBytes.length = messageLength-currentByte; - - handlerSocket.receive(remainingBytes); - - /* Increment counter of received bytes */ - currentByte += remainingBytes.length; - - /* Append the received bytes to the FULL message buffer */ - fullMessage ~= remainingBytes; - - writeln("Received ", currentByte, "/", cast(uint)messageLength, " bytes"); - } - else - { - /* Increment counter of received bytes */ - currentByte += bytesReceived; - - - /* Append the received bytes to the FULL message buffer */ - fullMessage ~= tempBuffer[0..bytesReceived]; - - /* TODO: Bug when over send, we must not allow this */ - - - writeln("Received ", currentByte, "/", cast(uint)messageLength, " bytes"); - - handlerSocket.receive(tempBuffer); - } - } - } - - - writeln("MEssage ", fullMessage); - - //int messageLength = 0; - - /* TODO: Loop for collect message */ - - /* TODO: So now we have to think about what the hell it means - * for a response to be received, like cool and all, but we need - * the server to now do something. - */ - - - /* TODO: Set dispatchStatus */ - } - else - { - /* TODO: Error handling */ - debugPrint("No message handler for payload type \"" ~ payloadType ~ "\" found."); - dispatchStatus = false; - } - - /* TODO: Set return value */ - debugPrint("Dispatch status: " ~ to!(string)(dispatchStatus)); - - return dispatchStatus; - } - private JSONValue handlerRun(MessageHandler chosenHandler, JSONValue payload) {