diff --git a/Foundation Web Core/src/com/foundation/web/server/WebServer.java b/Foundation Web Core/src/com/foundation/web/server/WebServer.java index cabd561..7f70524 100644 --- a/Foundation Web Core/src/com/foundation/web/server/WebServer.java +++ b/Foundation Web Core/src/com/foundation/web/server/WebServer.java @@ -293,7 +293,7 @@ public class WebServer { /** Whether the socket is currently being used by a thread designated by the network listener thread to read or write to the socket. Currently the socket type we use in Java only allows one thread to read and write at a time. Note: Always synchronize on key before using this attribute. */ private boolean isUsed = false; /** The SelectionKey flags that will be used when the NetworkListener thread finishes processing the input/output of a message. The thread can safely change these flags without synchronizing. */ - private int flags = 0; + //private int flags = 0; /** A socket context related to this one (when two are tied together such that data from one immediately is sent to the other). */ protected AbstractSocketContext relatedSocketContext = null; @@ -334,7 +334,7 @@ public class WebServer { /** * Updates the write flag status. * @param requiresWrite Whether a write is required. - */ + * protected void flagWrite(boolean requiresWrite) { synchronized(key) { boolean hasWrite = (flags & SelectionKey.OP_WRITE) != 0; @@ -342,29 +342,12 @@ public class WebServer { if(hasWrite != requiresWrite) { flags ^= SelectionKey.OP_WRITE; }//if// - /* - if(key.isValid()) { - int ops = key.interestOps(); - boolean hasWrite = (ops & SelectionKey.OP_WRITE) != 0; - - if(requiresWrite) { - if(!hasWrite) { - key.interestOps(ops | SelectionKey.OP_WRITE); - }//if// - }//if// - else { - if(hasWrite) { - key.interestOps(ops ^ SelectionKey.OP_WRITE); - }//if// - }//else// - }//if// - */ }//synchronized// }//flagWrite()// /** * Updates the read flag status. * @param requiresRead Whether a read is required. - */ + * protected void flagRead(boolean requiresRead) { synchronized(key) { boolean hasRead = (flags & SelectionKey.OP_READ) != 0; @@ -372,23 +355,6 @@ public class WebServer { if(hasRead != requiresRead) { flags ^= SelectionKey.OP_READ; }//if// - /* - if(key.isValid()) { - int ops = key.interestOps(); - boolean hasRead = (ops & SelectionKey.OP_READ) != 0; - - if(requiresRead) { - if(!hasRead) { - key.interestOps(ops | SelectionKey.OP_READ); - }//if// - }//if// - else { - if(hasRead) { - key.interestOps(ops ^ SelectionKey.OP_READ); - }//if// - }//else// - }//if// - */ }//synchronized// }//flagWrite()// protected void flagReadWrite(boolean requiresRead, boolean requiresWrite) { @@ -403,37 +369,6 @@ public class WebServer { if(hasWrite != requiresWrite) { flags ^= SelectionKey.OP_WRITE; }//if// - /* - if(key.isValid()) { - int ops = key.interestOps(); - boolean hasRead = (ops & SelectionKey.OP_READ) != 0; - boolean hasWrite = (ops & SelectionKey.OP_WRITE) != 0; - - if(requiresRead) { - if(!hasRead) { - ops |= SelectionKey.OP_READ; - }//if// - }//if// - else { - if(hasRead) { - ops ^= SelectionKey.OP_READ; - }//if// - }//else// - - if(requiresWrite) { - if(!hasWrite) { - ops |= SelectionKey.OP_WRITE; - }//if// - }//if// - else { - if(hasWrite) { - ops ^= SelectionKey.OP_WRITE; - }//if// - }//else// - - key.interestOps(ops); - }//if// - */ }//synchronized// }//flagReadWrite()// protected void flagReadWrite() { @@ -599,12 +534,7 @@ public class WebServer { }//if// //If we were able to send all the message data, then flag to read the response from the remote server (if more data comes in from the client, we will change this flag).// - if(pendingMessageBuffer == null) { - flagReadOnly(); - }//if// - else { - flagReadWrite(); - }//else// + //if(pendingMessageBuffer == null) flagReadOnly(); else flagReadWrite(); }//processResponses()// /* (non-Javadoc) * @see com.foundation.web.server.WebServer.AbstractSocketContext#processRequest() @@ -638,7 +568,7 @@ public class WebServer { }//while// //Always keep the read flag up for pass through sockets (leave the write flag alone).// - flagRead(true); + //flagRead(true); }//processRequest()// /* (non-Javadoc) * @see com.foundation.web.server.WebServer.AbstractSocketContext#passThrough(java.nio.ByteBuffer) @@ -655,7 +585,7 @@ public class WebServer { //Chain the message into the linked list. if(lastAddedMessageBuffer == null) { pendingMessageBuffer = lastAddedMessageBuffer = message; - flagReadWrite(); + //flagReadWrite(); }//if// else { lastAddedMessageBuffer.setNext(message); @@ -1173,7 +1103,6 @@ public class WebServer { //Chain the message into the linked list. if(lastAddedMessageBuffer == null || pendingOutboundMessage == null) { pendingOutboundMessage = lastAddedMessageBuffer = message; - flagWrite(true); }//if// else { lastAddedMessageBuffer.setNext(message); @@ -1190,8 +1119,6 @@ public class WebServer { //Synchronized to avoid multiple threads accessing the pendingOutboundMessage chain at one time and updating the write flag out of order (could happen if we enabled request chaining over a single socket).// synchronized(this) { writeClientResponse(); - //Set the write flag if we have more to write.// - flagReadWrite(true, pendingOutboundMessage != null); }//synchronized// }//if// else if(isWebsocket) { @@ -1204,7 +1131,7 @@ public class WebServer { }//else if// else { //Go directly to writing the client response if we are just passing everything through to another process.// - if(internalProcessResponses()) flagReadOnly(); else flagReadWrite(); + internalProcessResponses(); }//else// }//processCurrentResponse()// /** @@ -1334,7 +1261,7 @@ public class WebServer { /** * @return */ - private synchronized boolean internalProcessResponses() { + private synchronized void internalProcessResponses() { boolean finishedSending = true; //Keep sending responses while the buffers are not full and there is another response to send.// @@ -1374,7 +1301,7 @@ public class WebServer { }//if// }//while// - return finishedSending; + //if(finishedSending) flagReadOnly(); else flagReadWrite(); }//processCurrentResponse()// /** * Sends a response to the client. @@ -1928,7 +1855,7 @@ public class WebServer { }//while// }//else// - if(requiresRead) flagReadOnly(); else flagReadWrite(); + //if(requiresRead) flagReadOnly(); else flagReadWrite(); }//processRequest()// /* (non-Javadoc) * @see com.foundation.web.server.WebServer.AbstractSocketContext#hasPendingWrite() @@ -2204,7 +2131,7 @@ public class WebServer { //For now (so we don't have to require jdk7 yet) we will simply allow Speedy to queue up messages, but only read, process, and then write them one at a time. Most of the speed loss is in the waiting for the WRITE to finish before handling the next request (due to it being broken into packets and the mechanics of TCP), and that is generally minimal (speed lose) since usually the bottleneck in speed is the browser's connection to the internet (most of us haven't got Gigabit Ethernet at home). Anyone with enough home juice to have this be a problem would only notice the difference for really porky websites (which is a problem in and of its self). //Not allowing either reads or writes to continue until all processing of this message is done.// - ((AbstractSocketContext) context).flags = key.interestOps(); + //((AbstractSocketContext) context).flags = key.interestOps(); ((AbstractSocketContext) context).isUsed = true; key.interestOps(0);