forked from apache/mina-sshd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apacheGH-524: SFTP: optimize SftpOutputStreamAsync
Give SftpOutPutStreamAsync a transferFrom operation to be able to read directly into a prepared SSH packet uffer. Previously, we always had to read into a general byte buffer, and then copy into the SSH packet. This extra data copy can be avoided. If the copy buffer size is such that the data fits into a single SSH packet, then this packet buffer can be encoded and sent directly without any further data copying. Simplify the implementation: since the stream always uses a PacketBuffer the code paths for other general byte buffers can simply be removed. Also enable reading the next buffer while the previous one is being sent. Use two buffers alternatingly; one being sent, the other being filled. Use this implementation also in SftpRemotePathChannel in its transferFrom() implementation. _Do_ close the stream there, otherwise the final ACKs may not be checked. Bug: apache#524
- Loading branch information
Showing
9 changed files
with
368 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
* @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> | ||
*/ | ||
public interface RawSftpClient { | ||
|
||
/** | ||
* @param cmd Command to send - <B>Note:</B> only lower 8-bits are used | ||
* @param buffer The {@link Buffer} containing the command data | ||
|
@@ -36,6 +37,8 @@ public interface RawSftpClient { | |
*/ | ||
int send(int cmd, Buffer buffer) throws IOException; | ||
|
||
SftpMessage write(int cmd, Buffer buffer) throws IOException; | ||
|
||
/** | ||
* @param id The expected request id | ||
* @return The received response {@link Buffer} containing the request id | ||
|
87 changes: 87 additions & 0 deletions
87
sshd-sftp/src/main/java/org/apache/sshd/sftp/client/SftpMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.sshd.sftp.client; | ||
|
||
import java.io.IOException; | ||
import java.time.Duration; | ||
import java.util.Objects; | ||
|
||
import org.apache.sshd.common.io.IoWriteFuture; | ||
|
||
/** | ||
* A representation of a written SFTP message. | ||
* | ||
* @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> | ||
*/ | ||
public class SftpMessage { | ||
|
||
private final int id; | ||
private final IoWriteFuture future; | ||
private final Duration timeout; | ||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param id SFTP message id | ||
* @param future {@link IoWriteFuture} of the SFTP message; can be used to wait until the message has been actually | ||
* sent | ||
* @param timeout the configured SFTP write timeout | ||
*/ | ||
public SftpMessage(int id, IoWriteFuture future, Duration timeout) { | ||
this.id = id; | ||
this.future = Objects.requireNonNull(future); | ||
this.timeout = Objects.requireNonNull(timeout); | ||
} | ||
|
||
/** | ||
* Retrieves the SFTP message id. | ||
* | ||
* @return the SFTP message id | ||
*/ | ||
public int getId() { | ||
return id; | ||
} | ||
|
||
/** | ||
* Retrieves the {@link IoWriteFuture} of the message; can be used to wait until the message has been actually sent. | ||
* | ||
* @return the {@link IoWriteFuture}, never {@code null} | ||
*/ | ||
public IoWriteFuture getFuture() { | ||
return future; | ||
} | ||
|
||
/** | ||
* Retrieves the write timeout configured when the message was sent. | ||
* | ||
* @return the timeout, never {@code null} | ||
*/ | ||
public Duration getTimeout() { | ||
return timeout; | ||
} | ||
|
||
/** | ||
* Waits with the configured timeout until the message has been sent. | ||
* | ||
* @throws IOException if the message could not be sent, or waiting is interrupted. | ||
*/ | ||
public void waitUntilSent() throws IOException { | ||
getFuture().verify(getTimeout()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.