Removed commented old code. Made one more minor change that might break things.
This commit is contained in:
@@ -292,8 +292,6 @@ public class WebServer {
|
||||
public SelectionKey key = null;
|
||||
/** 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;
|
||||
/** 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;
|
||||
/** 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;
|
||||
|
||||
@@ -331,64 +329,6 @@ public class WebServer {
|
||||
* Determines whether the socket has a pending write operation.
|
||||
*/
|
||||
protected abstract boolean hasPendingWrite();
|
||||
/**
|
||||
* 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;
|
||||
|
||||
if(hasWrite != requiresWrite) {
|
||||
flags ^= SelectionKey.OP_WRITE;
|
||||
}//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;
|
||||
|
||||
if(hasRead != requiresRead) {
|
||||
flags ^= SelectionKey.OP_READ;
|
||||
}//if//
|
||||
}//synchronized//
|
||||
}//flagWrite()//
|
||||
protected void flagReadWrite(boolean requiresRead, boolean requiresWrite) {
|
||||
synchronized(key) {
|
||||
boolean hasWrite = (flags & SelectionKey.OP_WRITE) != 0;
|
||||
boolean hasRead = (flags & SelectionKey.OP_READ) != 0;
|
||||
|
||||
if(hasRead != requiresRead) {
|
||||
flags ^= SelectionKey.OP_READ;
|
||||
}//if//
|
||||
|
||||
if(hasWrite != requiresWrite) {
|
||||
flags ^= SelectionKey.OP_WRITE;
|
||||
}//if//
|
||||
}//synchronized//
|
||||
}//flagReadWrite()//
|
||||
protected void flagReadWrite() {
|
||||
synchronized(key) {
|
||||
//if(key.isValid()) key.interestOps(SelectionKey.OP_READ | SelectionKey.OP_WRITE);
|
||||
flags = SelectionKey.OP_READ | SelectionKey.OP_WRITE;
|
||||
}//synchronized//
|
||||
}//flagReadWrite()//
|
||||
protected void flagWriteOnly() {
|
||||
synchronized(key) {
|
||||
//if(key.isValid()) key.interestOps(SelectionKey.OP_WRITE);
|
||||
flags = SelectionKey.OP_WRITE;
|
||||
}//synchronized//
|
||||
}//flagWriteOnly()//
|
||||
protected void flagReadOnly() {
|
||||
synchronized(key) {
|
||||
//if(key.isValid()) key.interestOps(SelectionKey.OP_READ);
|
||||
flags = SelectionKey.OP_READ;
|
||||
}//synchronized//
|
||||
}//flagReadOnly()//
|
||||
/**
|
||||
* Called to notify the network listener that a pending write operation exists for this socket.
|
||||
*/
|
||||
@@ -532,9 +472,6 @@ public class WebServer {
|
||||
}//else//
|
||||
}//while//
|
||||
}//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(); else flagReadWrite();
|
||||
}//processResponses()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.web.server.WebServer.AbstractSocketContext#processRequest()
|
||||
@@ -566,9 +503,6 @@ public class WebServer {
|
||||
break;
|
||||
}//else//
|
||||
}//while//
|
||||
|
||||
//Always keep the read flag up for pass through sockets (leave the write flag alone).//
|
||||
//flagRead(true);
|
||||
}//processRequest()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.web.server.WebServer.AbstractSocketContext#passThrough(java.nio.ByteBuffer)
|
||||
@@ -585,7 +519,6 @@ public class WebServer {
|
||||
//Chain the message into the linked list.
|
||||
if(lastAddedMessageBuffer == null) {
|
||||
pendingMessageBuffer = lastAddedMessageBuffer = message;
|
||||
//flagReadWrite();
|
||||
}//if//
|
||||
else {
|
||||
lastAddedMessageBuffer.setNext(message);
|
||||
@@ -1300,8 +1233,6 @@ public class WebServer {
|
||||
}//else//
|
||||
}//if//
|
||||
}//while//
|
||||
|
||||
//if(finishedSending) flagReadOnly(); else flagReadWrite();
|
||||
}//processCurrentResponse()//
|
||||
/**
|
||||
* Sends a response to the client.
|
||||
@@ -1567,7 +1498,8 @@ public class WebServer {
|
||||
close();
|
||||
}//catch//
|
||||
|
||||
return sendMore;
|
||||
//The pending outbound message should be set to null if the whole message could be sent.//
|
||||
return pendingOutboundMessage == null;
|
||||
}//writeClientResponse()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.web.server.WebServer.AbstractSocketContext#processRequest()
|
||||
@@ -1854,8 +1786,6 @@ public class WebServer {
|
||||
}//else//
|
||||
}//while//
|
||||
}//else//
|
||||
|
||||
//if(requiresRead) flagReadOnly(); else flagReadWrite();
|
||||
}//processRequest()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.web.server.WebServer.AbstractSocketContext#hasPendingWrite()
|
||||
@@ -2131,7 +2061,6 @@ 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).isUsed = true;
|
||||
key.interestOps(0);
|
||||
|
||||
@@ -2180,7 +2109,6 @@ public class WebServer {
|
||||
if(selectionKey.isValid()) {
|
||||
//Always flag the socket for reading, only flag the socket for writing if a pending write operation exists.//
|
||||
selectionKey.interestOps(SelectionKey.OP_READ | (((AbstractSocketContext) context).hasPendingWrite() ? SelectionKey.OP_WRITE : 0));
|
||||
//selectionKey.interestOps(((AbstractSocketContext) context).flags);
|
||||
}//if//
|
||||
else {
|
||||
Debug.log(new RuntimeException("Woops! Somehow the selection key isn't valid, but the socket isn't closed either!"));
|
||||
|
||||
Reference in New Issue
Block a user