You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2009/07/27 08:56:11 UTC

svn commit: r798042 - in /mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel: ChannelPipedInputStream.java ChannelPipedOutputStream.java

Author: gnodet
Date: Mon Jul 27 06:56:11 2009
New Revision: 798042

URL: http://svn.apache.org/viewvc?rev=798042&view=rev
Log:
SSHD-34: ChannelPipedInputStream/ChannelPipedOutputStream doesn't handle EOF correctly

Modified:
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedOutputStream.java

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java?rev=798042&r1=798041&r2=798042&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedInputStream.java Mon Jul 27 06:56:11 2009
@@ -35,6 +35,12 @@
     private final Buffer buffer = new Buffer();
     private final byte[] b = new byte[1];
     private boolean closed;
+    /**
+     * {@link ChannelPipedOutputStream} is already closed and so we will not receive additional data.
+     * This is different from the {@link #closed}, which indicates that the reader of this {@link InputStream}
+     * will not be reading data any more.
+     */
+    private boolean writerClosed;
 
     public ChannelPipedInputStream(Window localWindow) {
         this.localWindow = localWindow;
@@ -61,6 +67,9 @@
                 if (buffer.available() > 0) {
                     break;
                 }
+                if (writerClosed) {
+                    return -1; // no more data to read
+                }
                 try {
                     buffer.wait();
                 } catch (InterruptedException e) {
@@ -80,6 +89,13 @@
         return len;
     }
 
+    protected void eof() {
+        synchronized (buffer) {
+            writerClosed = true;
+            buffer.notifyAll();
+        }
+    }
+
     @Override
     public void close() throws IOException {
         synchronized (buffer) {
@@ -90,7 +106,7 @@
 
     public void receive(byte[] bytes, int off, int len) throws IOException {
         synchronized (buffer) {
-            if (closed) {
+            if (writerClosed || closed) {
                 throw new IOException("Pipe closed");
             }
             buffer.putRawBytes(bytes, off, len);

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedOutputStream.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedOutputStream.java?rev=798042&r1=798041&r2=798042&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedOutputStream.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/common/channel/ChannelPipedOutputStream.java Mon Jul 27 06:56:11 2009
@@ -30,6 +30,7 @@
 
     private final ChannelPipedInputStream sink;
     private final byte[] b = new byte[1];
+    private boolean closed;
 
     public ChannelPipedOutputStream(ChannelPipedInputStream sink) {
         this.sink = sink;
@@ -49,6 +50,7 @@
 
     @Override
     public void close() throws IOException {
-        sink.close();
+        sink.eof();
+        closed = true;
     }
 }