Fixed socket flagging bug that threw exceptions when flagging to read/write to a socket that has closed.
This commit is contained in:
@@ -326,19 +326,21 @@ public class WebServer {
|
||||
*/
|
||||
protected void flagWrite(boolean requiresWrite) {
|
||||
synchronized(key) {
|
||||
if(key.isValid()) {
|
||||
int ops = key.interestOps();
|
||||
boolean hasWrite = (ops & SelectionKey.OP_WRITE) != 0;
|
||||
|
||||
if(requiresWrite) {
|
||||
if(!hasWrite) {
|
||||
if(key.isValid()) key.interestOps(ops | SelectionKey.OP_WRITE);
|
||||
key.interestOps(ops | SelectionKey.OP_WRITE);
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
if(hasWrite) {
|
||||
if(key.isValid()) key.interestOps(ops ^ SelectionKey.OP_WRITE);
|
||||
key.interestOps(ops ^ SelectionKey.OP_WRITE);
|
||||
}//if//
|
||||
}//else//
|
||||
}//if//
|
||||
}//synchronized//
|
||||
}//flagWrite()//
|
||||
/**
|
||||
@@ -347,23 +349,26 @@ public class WebServer {
|
||||
*/
|
||||
protected void flagRead(boolean requiresRead) {
|
||||
synchronized(key) {
|
||||
if(key.isValid()) {
|
||||
int ops = key.interestOps();
|
||||
boolean hasRead = (ops & SelectionKey.OP_READ) != 0;
|
||||
|
||||
if(requiresRead) {
|
||||
if(!hasRead) {
|
||||
if(key.isValid()) key.interestOps(ops | SelectionKey.OP_READ);
|
||||
key.interestOps(ops | SelectionKey.OP_READ);
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
if(hasRead) {
|
||||
if(key.isValid()) key.interestOps(ops ^ SelectionKey.OP_READ);
|
||||
key.interestOps(ops ^ SelectionKey.OP_READ);
|
||||
}//if//
|
||||
}//else//
|
||||
}//if//
|
||||
}//synchronized//
|
||||
}//flagWrite()//
|
||||
protected void flagReadWrite(boolean requiresRead, boolean requiresWrite) {
|
||||
synchronized(key) {
|
||||
if(key.isValid()) {
|
||||
int ops = key.interestOps();
|
||||
boolean hasRead = (ops & SelectionKey.OP_READ) != 0;
|
||||
boolean hasWrite = (ops & SelectionKey.OP_WRITE) != 0;
|
||||
@@ -390,7 +395,8 @@ public class WebServer {
|
||||
}//if//
|
||||
}//else//
|
||||
|
||||
if(key.isValid()) key.interestOps(ops);
|
||||
key.interestOps(ops);
|
||||
}//if//
|
||||
}//synchronized//
|
||||
}//flagReadWrite()//
|
||||
protected void flagReadWrite() {
|
||||
@@ -2282,7 +2288,18 @@ public synchronized boolean start() throws IOException {
|
||||
}//else//
|
||||
|
||||
if(success) {
|
||||
networkListener = new NetworkListener(selector, 10);
|
||||
String threadCount = System.getProperty("webserver.listener.threads");
|
||||
int count = 10;
|
||||
|
||||
if(threadCount != null) {
|
||||
try {count = Integer.parseInt(threadCount);} catch(Throwable e) {Debug.log(e);}
|
||||
|
||||
if(count < 1) {
|
||||
count = 10;
|
||||
}//if//
|
||||
}//if//
|
||||
|
||||
networkListener = new NetworkListener(selector, count);
|
||||
networkListener.start();
|
||||
}//if//
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user