Commented out all the flagging code, leaving two possible bits of code that could cause an error.

This commit is contained in:
wcrisman
2014-12-07 21:19:05 -08:00
parent 866e8d8bbd
commit b6b8de62fb

View File

@@ -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 <code>key</code> before using this attribute. */ /** 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 <code>key</code> before using this attribute. */
private boolean isUsed = false; 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. */ /** 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). */ /** 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; protected AbstractSocketContext relatedSocketContext = null;
@@ -334,7 +334,7 @@ public class WebServer {
/** /**
* Updates the write flag status. * Updates the write flag status.
* @param requiresWrite Whether a write is required. * @param requiresWrite Whether a write is required.
*/ *
protected void flagWrite(boolean requiresWrite) { protected void flagWrite(boolean requiresWrite) {
synchronized(key) { synchronized(key) {
boolean hasWrite = (flags & SelectionKey.OP_WRITE) != 0; boolean hasWrite = (flags & SelectionKey.OP_WRITE) != 0;
@@ -342,29 +342,12 @@ public class WebServer {
if(hasWrite != requiresWrite) { if(hasWrite != requiresWrite) {
flags ^= SelectionKey.OP_WRITE; flags ^= SelectionKey.OP_WRITE;
}//if// }//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// }//synchronized//
}//flagWrite()// }//flagWrite()//
/** /**
* Updates the read flag status. * Updates the read flag status.
* @param requiresRead Whether a read is required. * @param requiresRead Whether a read is required.
*/ *
protected void flagRead(boolean requiresRead) { protected void flagRead(boolean requiresRead) {
synchronized(key) { synchronized(key) {
boolean hasRead = (flags & SelectionKey.OP_READ) != 0; boolean hasRead = (flags & SelectionKey.OP_READ) != 0;
@@ -372,23 +355,6 @@ public class WebServer {
if(hasRead != requiresRead) { if(hasRead != requiresRead) {
flags ^= SelectionKey.OP_READ; flags ^= SelectionKey.OP_READ;
}//if// }//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// }//synchronized//
}//flagWrite()// }//flagWrite()//
protected void flagReadWrite(boolean requiresRead, boolean requiresWrite) { protected void flagReadWrite(boolean requiresRead, boolean requiresWrite) {
@@ -403,37 +369,6 @@ public class WebServer {
if(hasWrite != requiresWrite) { if(hasWrite != requiresWrite) {
flags ^= SelectionKey.OP_WRITE; flags ^= SelectionKey.OP_WRITE;
}//if// }//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// }//synchronized//
}//flagReadWrite()// }//flagReadWrite()//
protected void flagReadWrite() { protected void flagReadWrite() {
@@ -599,12 +534,7 @@ public class WebServer {
}//if// }//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 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) { //if(pendingMessageBuffer == null) flagReadOnly(); else flagReadWrite();
flagReadOnly();
}//if//
else {
flagReadWrite();
}//else//
}//processResponses()// }//processResponses()//
/* (non-Javadoc) /* (non-Javadoc)
* @see com.foundation.web.server.WebServer.AbstractSocketContext#processRequest() * @see com.foundation.web.server.WebServer.AbstractSocketContext#processRequest()
@@ -638,7 +568,7 @@ public class WebServer {
}//while// }//while//
//Always keep the read flag up for pass through sockets (leave the write flag alone).// //Always keep the read flag up for pass through sockets (leave the write flag alone).//
flagRead(true); //flagRead(true);
}//processRequest()// }//processRequest()//
/* (non-Javadoc) /* (non-Javadoc)
* @see com.foundation.web.server.WebServer.AbstractSocketContext#passThrough(java.nio.ByteBuffer) * @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. //Chain the message into the linked list.
if(lastAddedMessageBuffer == null) { if(lastAddedMessageBuffer == null) {
pendingMessageBuffer = lastAddedMessageBuffer = message; pendingMessageBuffer = lastAddedMessageBuffer = message;
flagReadWrite(); //flagReadWrite();
}//if// }//if//
else { else {
lastAddedMessageBuffer.setNext(message); lastAddedMessageBuffer.setNext(message);
@@ -1173,7 +1103,6 @@ public class WebServer {
//Chain the message into the linked list. //Chain the message into the linked list.
if(lastAddedMessageBuffer == null || pendingOutboundMessage == null) { if(lastAddedMessageBuffer == null || pendingOutboundMessage == null) {
pendingOutboundMessage = lastAddedMessageBuffer = message; pendingOutboundMessage = lastAddedMessageBuffer = message;
flagWrite(true);
}//if// }//if//
else { else {
lastAddedMessageBuffer.setNext(message); 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 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) { synchronized(this) {
writeClientResponse(); writeClientResponse();
//Set the write flag if we have more to write.//
flagReadWrite(true, pendingOutboundMessage != null);
}//synchronized// }//synchronized//
}//if// }//if//
else if(isWebsocket) { else if(isWebsocket) {
@@ -1204,7 +1131,7 @@ public class WebServer {
}//else if// }//else if//
else { else {
//Go directly to writing the client response if we are just passing everything through to another process.// //Go directly to writing the client response if we are just passing everything through to another process.//
if(internalProcessResponses()) flagReadOnly(); else flagReadWrite(); internalProcessResponses();
}//else// }//else//
}//processCurrentResponse()// }//processCurrentResponse()//
/** /**
@@ -1334,7 +1261,7 @@ public class WebServer {
/** /**
* @return * @return
*/ */
private synchronized boolean internalProcessResponses() { private synchronized void internalProcessResponses() {
boolean finishedSending = true; boolean finishedSending = true;
//Keep sending responses while the buffers are not full and there is another response to send.// //Keep sending responses while the buffers are not full and there is another response to send.//
@@ -1374,7 +1301,7 @@ public class WebServer {
}//if// }//if//
}//while// }//while//
return finishedSending; //if(finishedSending) flagReadOnly(); else flagReadWrite();
}//processCurrentResponse()// }//processCurrentResponse()//
/** /**
* Sends a response to the client. * Sends a response to the client.
@@ -1928,7 +1855,7 @@ public class WebServer {
}//while// }//while//
}//else// }//else//
if(requiresRead) flagReadOnly(); else flagReadWrite(); //if(requiresRead) flagReadOnly(); else flagReadWrite();
}//processRequest()// }//processRequest()//
/* (non-Javadoc) /* (non-Javadoc)
* @see com.foundation.web.server.WebServer.AbstractSocketContext#hasPendingWrite() * @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). //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.// //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; ((AbstractSocketContext) context).isUsed = true;
key.interestOps(0); key.interestOps(0);