Coder Social home page Coder Social logo

增加任务状态的建议 about ssh-rs HOT 1 OPEN

GZMaike avatar GZMaike commented on May 27, 2024
增加任务状态的建议

from ssh-rs.

Comments (1)

HsuJv avatar HsuJv commented on May 27, 2024

感谢您的提议。

关于您提议的三点,

  1. 中断:在run_local模式下,所有操作都需要同步完成,所以无论是scp还是exec都无法增加这个api,但是在run_backend模式下,或许可以增加类似的api。对于SSH来说,用户每开启一个channel,在服务器端都是并发执行的,所以如果只是为了多任务执行,可以使用run_backend模式同时打开多个channel,如果是为了阻止先前命令产生的副作用,那还是需要一个cancel或者abort的api,之前设计的时候没有考虑到。
  2. scp传输完成率:基于当前的设计,local模式或许可以在log里面增加相关打印,但是依然是前述问题,因为同步执行,无法提供单独api。backend模式目前的处理是先把文件全部读入内存然后提交到后台线程进行传输,所以可以提供所需api,会在后续更新中留意。
  3. 异步:如果只是单纯的指异步地执行ssh的相关操作,那么run_backend模式已经有了相关实现,保留同步执行的目的是为了兼容单线程执行环境(WASI,虽然目前对WASI的适配还在进行中)。如果是指async关键词的异步代码,这个改动或许有些巨大,需要把所有使用where S: Read + Write签名的方法全部重写,目前好像还没有一个好的方案能用同一套底层代码同时支持同步和异步io,关于这个改动是否要进行还在考虑中,或许会新开一个库来实现,因为并不是所有场景都适合引入异步进行时。

如果还有更多建议与问题,烦请告知

BRs.

P.S. 关于并发执行的POC,您可以尝试

use ssh_rs::ssh;

fn main() {
    ssh::enable_log();

    let mut session = ssh::create_session()
        .username("ubuntu")
        .password("password")
        .private_key_path("./id_rsa")
        .connect("127.0.0.1:22")
        .unwrap()
        .run_backend();
    let exec = session.open_exec().unwrap();
    let exec2 = session.open_exec().unwrap();

    const CMD: &str = "sleep 10 && date";

    // send the command to server
    println!("Send command {}", CMD);
    exec.send_command(CMD).unwrap();
    exec2.send_command(CMD).unwrap();

    // process other data
    println!("Do someother thing");

    // get command result
    let vec: Vec<u8> = exec.get_result().unwrap();
    println!("{}", String::from_utf8(vec).unwrap());
    let vec2: Vec<u8> = exec2.get_result().unwrap();
    println!("{}", String::from_utf8(vec2).unwrap());


    // Close session.
    session.close();
}

from ssh-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.