2018-04-02 17:42:57 -04:00
|
|
|
use std::{
|
|
|
|
time,
|
|
|
|
path::PathBuf,
|
|
|
|
};
|
|
|
|
|
|
|
|
use super::base::Connection;
|
|
|
|
use error::Result;
|
|
|
|
|
2018-04-03 06:14:12 -04:00
|
|
|
use named_pipe::PipeClient;
|
2018-04-02 17:42:57 -04:00
|
|
|
|
|
|
|
pub struct WindowsConnection {
|
|
|
|
socket: PipeClient,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Connection for WindowsConnection {
|
2018-04-03 06:03:08 -04:00
|
|
|
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 })
|
|
|
|
}
|
|
|
|
|
2018-04-03 06:03:08 -04:00
|
|
|
fn ipc_path() -> PathBuf {
|
|
|
|
PathBuf::from(r"\\.\pipe\")
|
2018-04-02 17:42:57 -04:00
|
|
|
}
|
|
|
|
|
2018-04-03 06:03:08 -04:00
|
|
|
fn socket(&mut self) -> &mut Self::Socket {
|
|
|
|
&mut self.socket
|
2018-04-02 17:42:57 -04:00
|
|
|
}
|
|
|
|
}
|