discord-rpc-client/src/connection/windows.rs

32 lines
739 B
Rust
Raw Normal View History

2022-02-03 09:52:53 -05:00
use std::{path::PathBuf, time};
2018-04-02 17:42:57 -04:00
use super::base::Connection;
use error::Result;
use named_pipe::PipeClient;
2018-04-02 17:42:57 -04:00
2022-02-03 09:52:53 -05:00
#[derive(Debug)]
2018-04-02 17:42:57 -04:00
pub struct WindowsConnection {
socket: PipeClient,
}
impl Connection for WindowsConnection {
type Socket = PipeClient;
2018-04-02 17:42:57 -04:00
fn connect() -> Result<Self> {
let connection_name = Self::socket_path(0);
let mut socket = PipeClient::connect(connection_name)?;
socket.set_write_timeout(Some(time::Duration::from_secs(30)));
socket.set_read_timeout(Some(time::Duration::from_secs(30)));
Ok(Self { socket })
}
fn ipc_path() -> PathBuf {
PathBuf::from(r"\\.\pipe\")
2018-04-02 17:42:57 -04:00
}
fn socket(&mut self) -> &mut Self::Socket {
&mut self.socket
2018-04-02 17:42:57 -04:00
}
}