From 541698f45271f3da573907140abff0956920be40 Mon Sep 17 00:00:00 2001 From: rasul Date: Mon, 6 Apr 2020 10:15:53 -0500 Subject: [PATCH] add a close() function to close the connection --- src/client.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index 5de411c..c40dbf0 100644 --- a/src/client.rs +++ b/src/client.rs @@ -2,15 +2,16 @@ use std::fmt; use std::io::{BufRead, BufReader, BufWriter, ErrorKind, Write}; -use std::net::SocketAddr; +use std::net::{Shutdown, SocketAddr}; use log::error; -use mio::Token; use mio::net::TcpStream; +use mio::Token; use crate::result::RudeResult; use crate::state::*; +use crate::try_log; /// `Client` struct for storing information about a connected client, also /// a few helper functions for communicating with the client. @@ -83,4 +84,11 @@ impl Client { fn prompt(&self) -> &str { "\n> " } + + pub fn close(&self) -> RudeResult<()> { + Ok(try_log!( + self.socket.shutdown(Shutdown::Both), + "Unable to close socket" + )) + } }