Align HTTP NIO with BIO and APR and hold a reference to the socket wrapper not the...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 6 Aug 2011 20:56:54 +0000 (20:56 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 6 Aug 2011 20:56:54 +0000 (20:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1154584 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/http11/Http11NioProcessor.java

index 2eb0f99..b076a8d 100644 (file)
@@ -106,7 +106,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
     /**
      * Socket associated with the current connection.
      */
-    protected NioChannel socket = null;
+    protected SocketWrapper<NioChannel> socket = null;
 
 
     // --------------------------------------------------------- Public Methods
@@ -126,7 +126,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
         int keepAliveTimeout = endpoint.getKeepAliveTimeout();
 
         RequestInfo rp = request.getRequestProcessor();
-        final NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
+        final NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getSocket().getAttachment(false);
         try {
             rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE);
             error = !adapter.event(request, response, status);
@@ -172,7 +172,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
 
     @Override
     protected void resetTimeouts() {
-        final NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
+        final NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getSocket().getAttachment(false);
         if (!error && attach != null &&
                 asyncStateMachine.isAsyncDispatching()) {
             long soTimeout = endpoint.getSoTimeout();
@@ -204,9 +204,9 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
         rp.setStage(org.apache.coyote.Constants.STAGE_PARSE);
 
         // Setting up the socket
-        this.socket = socket.getSocket();
-        inputBuffer.setSocket(this.socket);
-        outputBuffer.setSocket(this.socket);
+        this.socket = socket;
+        inputBuffer.setSocket(this.socket.getSocket());
+        outputBuffer.setSocket(this.socket.getSocket());
         inputBuffer.setSelectorPool(((NioEndpoint)endpoint).getSelectorPool());
         outputBuffer.setSelectorPool(((NioEndpoint)endpoint).getSelectorPool());
 
@@ -429,7 +429,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
 
             comet = false;
             cometClose = true;
-            SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
+            SelectionKey key = socket.getSocket().getIOChannel().keyFor(socket.getSocket().getPoller().getSelector());
             if ( key != null ) {
                 NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment) key.attachment();
                 if ( attach!=null && attach.getComet()) {
@@ -452,7 +452,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
 
             // Get remote host address
             if ((remoteAddr == null) && (socket != null)) {
-                InetAddress inetAddr = socket.getIOChannel().socket().getInetAddress();
+                InetAddress inetAddr = socket.getSocket().getIOChannel().socket().getInetAddress();
                 if (inetAddr != null) {
                     remoteAddr = inetAddr.getHostAddress();
                 }
@@ -463,7 +463,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
 
             // Get local host name
             if ((localName == null) && (socket != null)) {
-                InetAddress inetAddr = socket.getIOChannel().socket().getLocalAddress();
+                InetAddress inetAddr = socket.getSocket().getIOChannel().socket().getLocalAddress();
                 if (inetAddr != null) {
                     localName = inetAddr.getHostName();
                 }
@@ -474,7 +474,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
 
             // Get remote host name
             if ((remoteHost == null) && (socket != null)) {
-                InetAddress inetAddr = socket.getIOChannel().socket().getInetAddress();
+                InetAddress inetAddr = socket.getSocket().getIOChannel().socket().getInetAddress();
                 if (inetAddr != null) {
                     remoteHost = inetAddr.getHostName();
                 }
@@ -491,21 +491,21 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
         } else if (actionCode == ActionCode.REQ_LOCAL_ADDR_ATTRIBUTE) {
 
             if (localAddr == null)
-               localAddr = socket.getIOChannel().socket().getLocalAddress().getHostAddress();
+               localAddr = socket.getSocket().getIOChannel().socket().getLocalAddress().getHostAddress();
 
             request.localAddr().setString(localAddr);
 
         } else if (actionCode == ActionCode.REQ_REMOTEPORT_ATTRIBUTE) {
 
             if ((remotePort == -1 ) && (socket !=null)) {
-                remotePort = socket.getIOChannel().socket().getPort();
+                remotePort = socket.getSocket().getIOChannel().socket().getPort();
             }
             request.setRemotePort(remotePort);
 
         } else if (actionCode == ActionCode.REQ_LOCALPORT_ATTRIBUTE) {
 
             if ((localPort == -1 ) && (socket !=null)) {
-                localPort = socket.getIOChannel().socket().getLocalPort();
+                localPort = socket.getSocket().getIOChannel().socket().getLocalPort();
             }
             request.setLocalPort(localPort);
 
@@ -547,7 +547,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
                     .setLimit(maxSavePostSize);
                 inputBuffer.addActiveFilter
                     (inputFilters[Constants.BUFFERED_FILTER]);
-                SecureNioChannel sslChannel = (SecureNioChannel) socket;
+                SecureNioChannel sslChannel = (SecureNioChannel) socket.getSocket();
                 SSLEngine engine = sslChannel.getSslEngine();
                 if (!engine.getNeedClientAuth()) {
                     // Need to re-negotiate SSL connection
@@ -582,17 +582,17 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
         } else if (actionCode == ActionCode.COMET_END) {
             comet = false;
         }  else if (actionCode == ActionCode.COMET_CLOSE) {
-            if (socket==null || socket.getAttachment(false)==null) return;
-            NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
+            if (socket==null || socket.getSocket().getAttachment(false)==null) return;
+            NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getSocket().getAttachment(false);
             attach.setCometOps(NioEndpoint.OP_CALLBACK);
             //notify poller if not on a tomcat thread
             RequestInfo rp = request.getRequestProcessor();
             if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) //async handling
-                socket.getPoller().add(socket);
+                socket.getSocket().getPoller().add(socket.getSocket());
         } else if (actionCode == ActionCode.COMET_SETTIMEOUT) {
             if (param==null) return;
-            if (socket==null || socket.getAttachment(false)==null) return;
-            NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
+            if (socket==null || socket.getSocket().getAttachment(false)==null) return;
+            NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getSocket().getAttachment(false);
             long timeout = ((Long)param).longValue();
             //if we are not piggy backing on a worker thread, set the timeout
             RequestInfo rp = request.getRequestProcessor();
@@ -600,19 +600,19 @@ public class Http11NioProcessor extends AbstractHttp11Processor<NioChannel> {
                 attach.setTimeout(timeout);
         } else if (actionCode == ActionCode.ASYNC_COMPLETE) {
             if (asyncStateMachine.asyncComplete()) {
-                ((NioEndpoint)endpoint).processSocket(this.socket,
+                ((NioEndpoint)endpoint).processSocket(this.socket.getSocket(),
                         SocketStatus.OPEN, true);
             }
         } else if (actionCode == ActionCode.ASYNC_SETTIMEOUT) {
             if (param==null) return;
-            if (socket==null || socket.getAttachment(false)==null) return;
-            NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false);
+            if (socket==null || socket.getSocket().getAttachment(false)==null) return;
+            NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getSocket().getAttachment(false);
             long timeout = ((Long)param).longValue();
             //if we are not piggy backing on a worker thread, set the timeout
             attach.setTimeout(timeout);
         } else if (actionCode == ActionCode.ASYNC_DISPATCH) {
             if (asyncStateMachine.asyncDispatch()) {
-                ((NioEndpoint)endpoint).processSocket(this.socket,
+                ((NioEndpoint)endpoint).processSocket(this.socket.getSocket(),
                         SocketStatus.OPEN, true);
             }
         }