From d1d5671229598f376323a35f08f0b74c35bc6488 Mon Sep 17 00:00:00 2001 From: wcrisman Date: Sun, 28 Dec 2014 17:09:06 -0800 Subject: [PATCH] Fixed bug in the internalProcessResponses() in SocketContext where a message was flagged as needing to send more data because of already encrypted but unsent data, but was not properly sending the data because the currentOutboundMessage was closed and cleared. --- .../com/foundation/web/server/SocketContext.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Foundation Web Core/src/com/foundation/web/server/SocketContext.java b/Foundation Web Core/src/com/foundation/web/server/SocketContext.java index 4fd6a3e..a807852 100644 --- a/Foundation Web Core/src/com/foundation/web/server/SocketContext.java +++ b/Foundation Web Core/src/com/foundation/web/server/SocketContext.java @@ -726,26 +726,32 @@ private void loadNextWebsocketMessage() { * @return */ private synchronized void internalProcessResponses() { - boolean finishedSending = true; + boolean doneSending = false; //Keep sending responses while the buffers are not full and there is another response to send.// - while(finishedSending) { + while(!doneSending) { + boolean messageSent = true; + //If the socket is open then send the next buffer of data.// if(key.channel().isOpen()) { //Send the pending response object's prepared buffer of data.// - finishedSending = writeClientBoundMessage(); + messageSent = writeClientBoundMessage(); }//if// //Close the response if successfully sent, or if the socket is closed.// - if(finishedSending || !key.channel().isOpen()) { + if((messageSent || !key.channel().isOpen()) && currentOutboundMessage != null) { try {currentOutboundMessage.close();} catch(Throwable e) {} }//if// //If we finished sending the current response then load the next one.// - if(finishedSending) { + if(messageSent) { //TODO: Queue up the next outbound message. currentOutboundMessage = null; }//if// + + if(currentOutboundMessage == null) { + doneSending = true; + }//if// }//while// // //Keep sending responses while the buffers are not full and there is another response to send.//