You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/08/16 13:01:40 UTC

svn commit: r1514653 - /tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java

Author: markt
Date: Fri Aug 16 11:01:40 2013
New Revision: 1514653

URL: http://svn.apache.org/r1514653
Log:
Back-porting JSR-356
Add the locks to the SocketWrapper required to implement non-blocking IO

Modified:
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java?rev=1514653&r1=1514652&r2=1514653&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java Fri Aug 16 11:01:40 2013
@@ -16,6 +16,10 @@
  */
 package org.apache.tomcat.util.net;
 
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
+
 public class SocketWrapper<E> {
 
     protected volatile E socket;
@@ -28,8 +32,29 @@ public class SocketWrapper<E> {
     protected boolean async = false;
     protected boolean keptAlive = false;
 
+    /*
+     * Used if block/non-blocking is set at the socket level. The client is
+     * responsible for the thread-safe use of this field via the locks provided.
+     */
+    private volatile boolean blockingStatus = true;
+    private final Lock blockingStatusReadLock;
+    private final WriteLock blockingStatusWriteLock;
+
+    /*
+     * In normal servlet processing only one thread is allowed to access the
+     * socket at a time. That is controlled by a lock on the socket for both
+     * read and writes). When HTTP upgrade is used, one read thread and one
+     * write thread are allowed to access the socket concurrently. In this case
+     * the lock on the socket is used for reads and the lock below is used for
+     * writes.
+     */
+    private final Object writeThreadLock = new Object();
+
     public SocketWrapper(E socket) {
         this.socket = socket;
+        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+        this.blockingStatusReadLock = lock.readLock();
+        this.blockingStatusWriteLock =lock.writeLock();
     }
 
     public E getSocket() {
@@ -49,4 +74,13 @@ public class SocketWrapper<E> {
     public int decrementKeepAlive() { return (--keepAliveLeft);}
     public boolean isKeptAlive() {return keptAlive;}
     public void setKeptAlive(boolean keptAlive) {this.keptAlive = keptAlive;}
+    public boolean getBlockingStatus() { return blockingStatus; }
+    public void setBlockingStatus(boolean blockingStatus) {
+        this.blockingStatus = blockingStatus;
+    }
+    public Lock getBlockingStatusReadLock() { return blockingStatusReadLock; }
+    public WriteLock getBlockingStatusWriteLock() {
+        return blockingStatusWriteLock;
+    }
+    public Object getWriteThreadLock() { return writeThreadLock; }
 }



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