clean unused mutex

This commit is contained in:
Guillermo Roche 2022-09-30 00:58:10 +02:00
parent a698bbb14f
commit ffab5ed4a5

View File

@ -1,14 +1,14 @@
use std::net::TcpStream;
use std::io::prelude::*;
use std::thread;
use std::sync::{Arc, Mutex, RwLock};
use std::sync::{Arc, RwLock};
use crate::protocol;
pub mod guard;
pub struct Client<'a>{
client: Arc<Mutex<TcpStream>>,
server:Arc<Mutex<TcpStream>>,
client: TcpStream,
server:TcpStream,
hs: protocol::HandShake<'a>,
run : Arc<RwLock<bool>>,
}
@ -16,8 +16,8 @@ pub struct Client<'a>{
impl<'a> Client<'a> {
pub fn new(client: TcpStream, server: TcpStream, handshake: protocol::HandShake) -> Client{
Client {
client: Arc::new(Mutex::new(client)),
server: Arc::new(Mutex::new(server)),
client: client,
server: server,
hs: handshake,
run: Arc::new(RwLock::new(true)),
//threads: None,
@ -28,19 +28,18 @@ impl<'a> Client<'a> {
println!("len_pack {}", self.hs.get_host_name());
}
fn join_conexions_mutex(c1: Arc<Mutex<TcpStream>>,
c2: Arc<Mutex<TcpStream>>,
fn join_conexions_mutex(mut origin: TcpStream,
mut dest: TcpStream,
run: Arc<RwLock<bool>>){
let mut buf: [u8; 100000] = [0; 100000];
let mut client = c1.lock().unwrap().try_clone().unwrap();
let mut buf: [u8; 200] = [0; 200];
while *run.read().unwrap() {
let res=client.read(&mut buf);
let res=origin.read(&mut buf);
match res {
Ok(leng) => {
if leng == 0 {
*run.write().unwrap()=false;
}
match c2.lock().unwrap().write(&buf [.. leng]) {
match dest.write(&buf [.. leng]) {
Ok(_l) => {},
Err(_e) => *run.write().unwrap()=false,
}
@ -54,8 +53,8 @@ impl<'a> Client<'a> {
pub fn start_proxy(&self) -> (thread::JoinHandle<()>, thread::JoinHandle<()>) {
let c1 = self.client.clone();
let s1 = self.server.clone();
let c1 = self.client.try_clone().unwrap();
let s1 = self.server.try_clone().unwrap();
let r1 = self.run.clone();
let handler1 = thread::spawn( || {
Self::join_conexions_mutex(s1,
@ -63,8 +62,8 @@ impl<'a> Client<'a> {
r1)}
);
let c2 = self.client.clone();
let s2 = self.server.clone();
let c2 = self.client.try_clone().unwrap();
let s2 = self.server.try_clone().unwrap();
let r2 = self.run.clone();
let handler2 = thread::spawn( || {
Self::join_conexions_mutex(c2,