Server

Struct Server 

Source
pub struct Server { /* private fields */ }
Expand description

一个服务器,侦听传入的 Unix 域套接字 (UDS) 连接并处理命令。

Implementations§

Source§

impl Server

Source

pub fn new( shell_: Shell, uds_cmd_path_: String, uds_output_path_: String, ) -> Server

创建一个新的 Server 实例。

§Arguments
  • shell_ - 要在服务器上执行的 shell 实例。
  • uds_cmd_path_ - Unix 域套接字 (UDS) 路径,用于侦听命令。
  • uds_output_path_ - Unix 域套接字 (UDS) 路径,用于侦听输出。
§Returns

一个新的 Server 实例。

Examples found in repository?
examples/main.rs (lines 51-55)
36fn main() {
37    let mut shell = Shell::new();
38
39    reg_shell_cmd!(shell,
40        {"hello", print_hello},
41        {"add_two", add_two},
42        {"print_str", print_str},
43        {"add_seven", add_seven},
44        {"run_exit", exit}
45    );
46
47    let pid = get_self_pid();
48
49    println!("pid: {}", pid);
50
51    match Server::new(
52        shell,
53        format!("/tmp/rust_shell_cmd_{}", pid),
54        format!("/tmp/rust_shell_output_{}", pid),
55    )
56    .run()
57    {
58        Ok(_) => (),
59        Err(err) => println!("run err: {}", err),
60    }
61}
Source

pub fn run(&mut self) -> Result<(), String>

在 Server 实例上运行命令并处理输出。

§Returns

运行结果。

§Errors

如果命令线程或输出线程返回错误,则返回包含该错误的 Result。

Examples found in repository?
examples/main.rs (line 56)
36fn main() {
37    let mut shell = Shell::new();
38
39    reg_shell_cmd!(shell,
40        {"hello", print_hello},
41        {"add_two", add_two},
42        {"print_str", print_str},
43        {"add_seven", add_seven},
44        {"run_exit", exit}
45    );
46
47    let pid = get_self_pid();
48
49    println!("pid: {}", pid);
50
51    match Server::new(
52        shell,
53        format!("/tmp/rust_shell_cmd_{}", pid),
54        format!("/tmp/rust_shell_output_{}", pid),
55    )
56    .run()
57    {
58        Ok(_) => (),
59        Err(err) => println!("run err: {}", err),
60    }
61}

Trait Implementations§

Source§

impl Drop for Server

实现 Drop trait,以便在 Server 实例被丢弃时删除 Unix 域套接字 (UDS) 文件。

Source§

fn drop(&mut self)

当 Server 实例被丢弃时,此函数将被调用。 它将删除 uds_cmd_pathuds_output_path 所指向的 Unix 域套接字 (UDS) 文件。

Auto Trait Implementations§

§

impl Freeze for Server

§

impl RefUnwindSafe for Server

§

impl Send for Server

§

impl Sync for Server

§

impl Unpin for Server

§

impl UnwindSafe for Server

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.