Author: markt
Date: Sat Aug  6 20:56:54 2011
New Revision: 1154584

URL: http://svn.apache.org/viewvc?rev=1154584&view=rev
Log:
Align HTTP NIO with BIO and APR and hold a reference to the socket wrapper not 
the raw socket in the Processor.

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java

Modified: tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?rev=1154584&r1=1154583&r2=1154584&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Sat Aug  
6 20:56:54 2011
@@ -106,7 +106,7 @@ public class Http11NioProcessor extends 
     /**
      * 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 
         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 
 
     @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 
         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 
 
             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 
 
             // 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 
 
             // 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 
 
             // 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 
         } 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 
                     .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 
         } 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 
                 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);
             }
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to