diff --git a/Foundation Builder/Build Archives.launch b/Foundation Builder/Build Archives.launch index de0d980..87ac3af 100644 --- a/Foundation Builder/Build Archives.launch +++ b/Foundation Builder/Build Archives.launch @@ -1,7 +1,7 @@ - + @@ -15,6 +15,8 @@ + + diff --git a/Foundation Builder/builder/build.xml b/Foundation Builder/builder/build.xml index b1cdcea..61e95fb 100644 --- a/Foundation Builder/builder/build.xml +++ b/Foundation Builder/builder/build.xml @@ -113,7 +113,7 @@ - + diff --git a/Foundation Web Core/src/com/foundation/web/server/AbstractSocketContext.java b/Foundation Web Core/src/com/foundation/web/server/AbstractSocketContext.java index 06409fb..f478afb 100644 --- a/Foundation Web Core/src/com/foundation/web/server/AbstractSocketContext.java +++ b/Foundation Web Core/src/com/foundation/web/server/AbstractSocketContext.java @@ -95,6 +95,14 @@ protected abstract void passThrough(ByteBuffer buffer); * Closes the socket context and cleans up. */ protected abstract void close(); +/** + * Determines whether the socket context has been closed. + * Should synchronize on getLock() prior to calling this. + * @return Whether the socket context is closed. + */ +protected boolean isClosed() { + return !(key != null && key.channel().isOpen()); +}//isClosed()// /** * Gets the socket context related to this one (when two are tied together such that data from one immediately is sent to the other). * @return The related socket context, or null if none exists (data not forwarded to a remote server). diff --git a/Foundation Web Core/src/com/foundation/web/server/PassThroughSocketContext.java b/Foundation Web Core/src/com/foundation/web/server/PassThroughSocketContext.java index fb48689..90c9ee8 100644 --- a/Foundation Web Core/src/com/foundation/web/server/PassThroughSocketContext.java +++ b/Foundation Web Core/src/com/foundation/web/server/PassThroughSocketContext.java @@ -249,4 +249,10 @@ protected synchronized void close() { protected boolean hasPendingWrite() { return currentOutboundMessage != null; }//hasPendingWrite()// +/* (non-Javadoc) + * @see java.lang.Object#toString() + */ +public String toString() { + return "PassThroughSocketContext: " + (relatedSocketContext != null ? relatedSocketContext.toString() : "null"); +}//toString()// }//PassThroughSocketContext// \ No newline at end of file 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 b7f6b7f..9f3a53d 100644 --- a/Foundation Web Core/src/com/foundation/web/server/SocketContext.java +++ b/Foundation Web Core/src/com/foundation/web/server/SocketContext.java @@ -325,33 +325,39 @@ protected void writeOutgoingMessages() throws IOException { //Synchronized to avoid multiple threads accessing the currentOutboundMessage chain at one time.// synchronized(getLock()) { - if(currentOutboundMessage != outboundMessage) { - Debug.log(new RuntimeException("Cannot change the currentOutboundMessage while we are sending it!")); - }//if// - - //If we finished the message then load the next message, otherwise flag that we need to stop sending (buffers full - flag a write on the socket's key and wait).// - if(messageSent || (currentOutboundMessage != null && currentOutboundMessage.isClosed())) { - if(getWebServer().debug()) { - Debug.log(this.getId() + "|" + System.nanoTime() + "|The sent message was fully sent."); + if(!isClosed()) { + if(currentOutboundMessage != outboundMessage) { + Debug.log(new RuntimeException("Cannot change the currentOutboundMessage while we are sending it! {" + toString() + "}")); }//if// - //Close the message if possible.// - try {currentOutboundMessage.close();} catch(Throwable e) {} - //Load the next available message.// - currentOutboundMessage = currentOutboundMessage.getNext(); - if(currentOutboundMessage == null) lastOutboundMessage = null; - keepSending = hasPendingWrite() && key.channel().isOpen(); - outboundMessage = currentOutboundMessage; - - if(getWebServer().debug()) { - Debug.log(this.getId() + "|" + System.nanoTime() + "| Channel is open? " + key.channel().isOpen() + "; More message available? " + hasPendingWrite() + "; EncryptedWriteBuffer.remaining? " + encryptedWriteBuffer.remaining() + "."); + //If we finished the message then load the next message, otherwise flag that we need to stop sending (buffers full - flag a write on the socket's key and wait).// + if(messageSent || (currentOutboundMessage != null && currentOutboundMessage.isClosed())) { + if(getWebServer().debug()) { + Debug.log(this.getId() + "|" + System.nanoTime() + "|The sent message was fully sent."); + }//if// + + //Close the message if possible.// + try {currentOutboundMessage.close();} catch(Throwable e) {} + //Load the next available message.// + currentOutboundMessage = currentOutboundMessage.getNext(); + if(currentOutboundMessage == null) lastOutboundMessage = null; + keepSending = hasPendingWrite() && key.channel().isOpen(); + outboundMessage = currentOutboundMessage; + + if(getWebServer().debug()) { + Debug.log(this.getId() + "|" + System.nanoTime() + "| Channel is open? " + key.channel().isOpen() + "; More message available? " + hasPendingWrite() + "; EncryptedWriteBuffer.remaining? " + encryptedWriteBuffer.remaining() + "."); + }//if// }//if// + else { + if(getWebServer().debug()) { + Debug.log(this.getId() + "|" + System.nanoTime() + "|The sent message was only partially sent, stop sending for now."); + }//if// + + keepSending = false; + }//else// }//if// else { - if(getWebServer().debug()) { - Debug.log(this.getId() + "|" + System.nanoTime() + "|The sent message was only partially sent, stop sending for now."); - }//if// - + Debug.log(this.getId() + "|" + System.nanoTime() + "|Socket closed."); keepSending = false; }//else// }//synchronized// @@ -2245,6 +2251,6 @@ private int indexOf(byte[] source, byte[] pattern, int fromOffset) { * @see java.lang.Object#toString() */ public String toString() { - return "Domain: " + domain + "; SSL: " + (sslEngine != null) + "; Websocket: " + isWebsocket; + return "SocketContext: Domain: " + domain + "; SSL: " + (sslEngine != null) + "; Websocket: " + isWebsocket; }//toString()// }//SocketContext// \ No newline at end of file