Remove disconnect method from Connection
Use Drop implementation instead
This commit is contained in:
parent
caaae615f0
commit
ecd391a44e
|
@ -38,8 +38,6 @@ pub trait Connection: Sized {
|
|||
|
||||
fn connect() -> Result<Self>;
|
||||
|
||||
fn disconnect(&self) -> Result<()>;
|
||||
|
||||
fn socket_path(n: u8) -> PathBuf {
|
||||
Self::ipc_path().join(format!("discord-ipc-{}", n))
|
||||
}
|
||||
|
|
|
@ -20,17 +20,12 @@ impl Connection for UnixConnection {
|
|||
fn connect() -> Result<Self> {
|
||||
let connection_name = Self::socket_path(0);
|
||||
let socket = UnixStream::connect(connection_name)?;
|
||||
// socket.set_nonblocking(true)?;
|
||||
socket.set_nonblocking(true)?;
|
||||
socket.set_write_timeout(Some(time::Duration::from_secs(30)))?;
|
||||
socket.set_read_timeout(Some(time::Duration::from_secs(30)))?;
|
||||
Ok(Self { socket })
|
||||
}
|
||||
|
||||
fn disconnect(&self) -> Result<()> {
|
||||
self.socket.shutdown(Shutdown::Both)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ipc_path() -> PathBuf {
|
||||
let tmp = env::var("XDG_RUNTIME_DIR")
|
||||
.or_else(|_| env::var("TMPDIR"))
|
||||
|
@ -48,3 +43,10 @@ impl Connection for UnixConnection {
|
|||
&mut self.socket
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for UnixConnection {
|
||||
fn drop(&mut self) {
|
||||
self.socket.shutdown(Shutdown::Both)
|
||||
.expect("Failed to properly shut down socket");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,6 @@ impl Connection for WindowsConnection {
|
|||
Ok(Self { socket })
|
||||
}
|
||||
|
||||
fn disconnect(&self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ipc_path() -> PathBuf {
|
||||
PathBuf::from(r"\\.\pipe\")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue