use ugly_smart_lib::smart_pub::StdArc; use ugly_smart_lib::CTcpClient; use ugly_smart_lib::INetCallBack; use ugly_smart_lib::INetwork; use ugly_smart_lib::STcpClientParams; use crate::helper::init_log; #[tokio::test] async fn client_new_test() { struct MyClient { sender: ugly_smart_lib::smart_pub::ArcMutex>>>, } init_log(); impl INetCallBack> for MyClient { fn data_callback( self: ugly_smart_lib::smart_pub::StdArc, data: Vec, _handle: String, _serv_type: ugly_smart_lib::net_pub::ServiceType, ) { let sender_arc = self.sender.clone(); let sender_mutex = sender_arc.lock().unwrap(); match &*sender_mutex { Some(sender) => { sender.send(data).unwrap(); } None => {} } } fn state_callback( self: ugly_smart_lib::smart_pub::StdArc, _handle: String, state: ugly_smart_lib::net_pub::EConnectionState>, _serv_type: ugly_smart_lib::net_pub::ServiceType, ) { match state { ugly_smart_lib::net_pub::EConnectionState::Running(sender) => { let sender_arc = self.sender.clone(); let mut sender_mutex = sender_arc.lock().unwrap(); *sender_mutex = Some(sender); } _ => {} } } } let my_client = StdArc::new(MyClient { sender: ugly_smart_lib::smart_pub::StdArc::new(ugly_smart_lib::smart_pub::StdMutex::new(None)), }); let client_params = STcpClientParams { connection_addr: "127.0.0.1:8866".into(), call_back: Box::new(my_client), extra_params: "127.0.0.1:8866".into(), }; let client = StdArc::new(CTcpClient::new(client_params)); ugly_smart_lib::net_pub::spawn_and_log_error(client.clone().start()); tokio::time::sleep(std::time::Duration::from_secs(10)).await; ugly_smart_lib::net_pub::spawn_and_log_error(client.clone().stop()); tokio::time::sleep(std::time::Duration::from_secs(1)).await; }