Author: markt
Date: Sat Sep 18 18:09:48 2010
New Revision: 998509
URL: http://svn.apache.org/viewvc?rev=998509&view=rev
Log:
Re-factor JIO end point to look more like NIO end point. Moving stuff around,
processing order should remain the same.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=998509&r1=998508&r2=998509&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Sat Sep 18
18:09:48 2010
@@ -196,8 +196,19 @@ public class JIoEndpoint extends Abstrac
try {
// Accept the next incoming connection from the server
socket
Socket socket =
serverSocketFactory.acceptSocket(serverSocket);
- // Hand this socket off to an appropriate processor
- if (!processSocket(socket)) {
+
+ // Configure the socket
+ if (setSocketOptions(socket)) {
+ // Hand this socket off to an appropriate processor
+ if (!processSocket(socket)) {
+ // Close socket right away
+ try {
+ socket.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ } else {
// Close socket right away
try {
socket.close();
@@ -255,11 +266,17 @@ public class JIoEndpoint extends Abstrac
}
SocketState state = SocketState.OPEN;
- // Process the request from this socket
- if ( (!socket.isInitialized()) &&
(!setSocketOptions(socket.getSocket())) ) {
+
+ try {
+ // SSL handshake
+ serverSocketFactory.handshake(socket.getSocket());
+ } catch (Throwable t) {
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("endpoint.err.handshake"), t);
+ }
+ // Tell to close the socket
state = SocketState.CLOSED;
}
- socket.setInitialized(true);
if ( (state != SocketState.CLOSED) ) {
state =
(status==null)?handler.process(socket):handler.process(socket,status);
@@ -448,11 +465,11 @@ public class JIoEndpoint extends Abstrac
/**
- * Set the options for the current socket.
+ * Configure the socket.
*/
protected boolean setSocketOptions(Socket socket) {
- // Process the connection
-
+ serverSocketFactory.initSocket(socket);
+
try {
// 1: Set socket options: timeout, linger, etc
socketProperties.setProperties(socket);
@@ -468,25 +485,15 @@ public class JIoEndpoint extends Abstrac
// Close the socket
return false;
}
- try {
- // 2: SSL handshake
- serverSocketFactory.handshake(socket);
- } catch (Throwable t) {
- if (log.isDebugEnabled()) {
- log.debug(sm.getString("endpoint.err.handshake"), t);
- }
- // Tell to close the socket
- return false;
- }
return true;
}
-
+
/**
* Process given socket.
*/
protected boolean processSocket(Socket socket) {
- serverSocketFactory.initSocket(socket);
+ // Process the request from this socket
try {
SocketWrapper<Socket> wrapper = new SocketWrapper<Socket>(socket);
wrapper.setKeepAliveLeft(getMaxKeepAliveRequests());
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=998509&r1=998508&r2=998509&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Sat Sep 18
18:09:48 2010
@@ -580,6 +580,7 @@ public class NioEndpoint extends Abstrac
/**
* Stop the endpoint. This will cause all processing threads to stop.
*/
+ @Override
public void stop() {
if (!paused) {
pause();
@@ -643,6 +644,7 @@ public class NioEndpoint extends Abstrac
return selectorPool;
}
+ @Override
public boolean getUseSendfile() {
return useSendfile;
}
@@ -793,7 +795,8 @@ public class NioEndpoint extends Abstrac
//TODO FIXME - this is currently a blocking call, meaning
we will be blocking
//further accepts until there is a thread available.
if ( running && (!paused) && socket != null ) {
- //processSocket(socket);
+ // setSocketOptions() will add channel to the poller
+ // if successful
if (!setSocketOptions(socket)) {
try {
socket.socket().close();
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java?rev=998509&r1=998508&r2=998509&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java Sat Sep 18
18:09:48 2010
@@ -31,7 +31,6 @@ public class SocketWrapper<E> {
protected volatile int keepAliveLeft = 100;
protected boolean async = false;
protected boolean keptAlive = false;
- protected boolean initialized = false;
public AtomicBoolean processing = new AtomicBoolean(false);
public SocketWrapper(E socket) {
@@ -58,7 +57,4 @@ public class SocketWrapper<E> {
public int decrementKeepAlive() { return (--keepAliveLeft);}
public boolean isKeptAlive() {return keptAlive;}
public void setKeptAlive(boolean keptAlive) {this.keptAlive = keptAlive;}
- public boolean isInitialized() {return initialized;}
- public void setInitialized(boolean initialized) {this.initialized =
initialized;}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]