This is an automated email from the ASF dual-hosted git repository.

twolf pushed a commit to branch dev_3.0
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit a138b8607fa8b11dad431b08733ef6b753ea5826
Author: Thomas Wolf <tw...@apache.org>
AuthorDate: Thu Apr 24 21:06:03 2025 +0200

    Add Window.consumeAll()
    
    This provides a way to "close" a window without any race conditions:
    writes to the channel will be blocked.
---
 .../main/java/org/apache/sshd/common/channel/Window.java  | 15 +++++++++++++++
 .../java/org/apache/sshd/common/forward/SocksProxy.java   |  3 +--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java 
b/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
index 83a946f34..c5dd81981 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/Window.java
@@ -140,6 +140,21 @@ public abstract class Window extends AbstractLoggingBean 
implements ChannelHolde
      */
     public abstract long consume(long len) throws IOException;
 
+    /**
+     * Consume all bytes from the window.
+     *
+     * @return the number of bytes consumed
+     */
+    public long consumeAll() {
+        checkInitialized("consumeAll");
+        synchronized (lock) {
+            long current = size;
+            size = 0;
+            // No need to notify(): anyone waiting is waiting for > 0 anyway.
+            return current;
+        }
+    }
+
     protected void updateSize(long size) {
         BufferUtils.validateUint32Value(size, "Invalid updated size: %d", 
size);
         this.size = size;
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java 
b/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java
index 4736fe924..a779aa65f 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/SocksProxy.java
@@ -288,8 +288,7 @@ public class SocksProxy extends AbstractCloseable 
implements IoHandler {
                 service.registerChannel(channel);
                 // Open the channel, but don't accept input data yet!
                 LocalWindow window = channel.getLocalWindow();
-                long windowSize = window.getSize();
-                window.consume(windowSize);
+                long windowSize = window.consumeAll();
                 channel.open().addListener(f -> onChannelOpened(f, window, 
windowSize));
             } else {
                 if (debugEnabled) {

Reply via email to