tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1478576 - /tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
Date Thu, 02 May 2013 21:38:16 GMT
Author: markt
Date: Thu May  2 21:38:16 2013
New Revision: 1478576

URL: http://svn.apache.org/r1478576
Log:
Refactor in preparation to pull-up non-blocking functionality

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=1478576&r1=1478575&r2=1478576&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Thu May  2 21:38:16
2013
@@ -169,7 +169,6 @@ public class Http11NioProcessor extends 
 
     @Override
     public SocketState asyncDispatch(SocketStatus status) {
-        final NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getSocket().getAttachment(false);
 
 
         if (status == SocketStatus.OPEN_WRITE) {
@@ -180,17 +179,17 @@ public class Http11NioProcessor extends 
                         //System.out.println("Attempting data flush!!");
                         outputBuffer.flushBuffer(false);
                     }
+                    //return if we have more data to write
+                    if (registerForWrite()) {
+                        return SocketState.LONG;
+                    }
                 } catch (IOException x) {
                     if (log.isDebugEnabled()) log.debug("Unable to write async data.",x);
                     status = SocketStatus.ASYNC_WRITE_ERROR;
                     request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, x);
                 }
-                //return if we have more data to write
-                if (status == SocketStatus.OPEN_WRITE && isRegisteredForWrite(attach))
{
-                    return SocketState.LONG;
-                }
             } catch (IllegalStateException x) {
-                attach.interestOps(attach.interestOps() | SelectionKey.OP_WRITE);
+                registerForEvent(SelectionKey.OP_WRITE);
             }
         } else if (status == SocketStatus.OPEN_READ) {
             try {
@@ -204,46 +203,52 @@ public class Http11NioProcessor extends 
                     request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, x);
                 }
             } catch (IllegalStateException x) {
-                attach.interestOps(attach.interestOps() | SelectionKey.OP_READ);
+                registerForEvent(SelectionKey.OP_READ);
             }
         }
 
         SocketState state = super.asyncDispatch(status);
-        //return if we have more data to write
-        if (state == SocketState.LONG && isRegisteredForWrite(attach)) {
-            return SocketState.LONG;
-        } else {
-            return state;
+        if (state == SocketState.LONG) {
+            registerForWrite();
         }
+
+        return state;
     }
 
 
 
     @Override
-    public SocketState process(SocketWrapper<NioChannel> socketWrapper) throws IOException
{
+    public SocketState process(SocketWrapper<NioChannel> socketWrapper)
+            throws IOException {
         SocketState state = super.process(socketWrapper);
-        final NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getSocket().getAttachment(false);
-        //return if we have more data to write
-        if (attach != null && isRegisteredForWrite(attach)) {
-            return SocketState.LONG;
-        } else {
-            return state;
+        final NioEndpoint.KeyAttachment attach =
+                (NioEndpoint.KeyAttachment)socket.getSocket().getAttachment(
+                        false);
+        if (attach != null) {
+            registerForWrite();
         }
+        return state;
     }
 
 
-
-
-    protected boolean isRegisteredForWrite(KeyAttachment attach) {
-        //return if we have more data to write
+    protected boolean registerForWrite() {
+        // Register for write if we have more data to write
         if (outputBuffer.hasDataToWrite()) {
-            attach.interestOps(attach.interestOps() | SelectionKey.OP_WRITE);
+            registerForEvent(SelectionKey.OP_WRITE);
             return true;
         } else {
             return false;
         }
     }
 
+
+    protected void registerForEvent(int event) {
+        final NioEndpoint.KeyAttachment attach =
+                (NioEndpoint.KeyAttachment)socket.getSocket().getAttachment(false);
+        attach.interestOps(attach.interestOps() | event);
+    }
+
+
     @Override
     protected void resetTimeouts() {
         final NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getSocket().getAttachment(false);



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


Mime
View raw message