|
|
@@ -1,15 +1,16 @@
|
|
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
|
|
-use std::sync::{Arc, Mutex};
|
|
|
+use std::sync::Arc;
|
|
|
use std::sync::atomic::AtomicBool;
|
|
|
use std::time::Duration;
|
|
|
|
|
|
use chrono::Utc;
|
|
|
use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
|
|
|
-use futures_util::{future, pin_mut, SinkExt, StreamExt};
|
|
|
+use futures_util::{future, pin_mut, SinkExt, StreamExt};
|
|
|
use futures_util::stream::{SplitSink, SplitStream};
|
|
|
use ring::hmac;
|
|
|
use serde_json::json;
|
|
|
use tokio::net::TcpStream;
|
|
|
+use tokio::sync::Mutex;
|
|
|
use tokio_tungstenite::{connect_async, MaybeTlsStream, WebSocketStream};
|
|
|
use tokio_tungstenite::tungstenite::{Error, Message};
|
|
|
use tracing::trace;
|
|
|
@@ -24,8 +25,7 @@ pub enum HeartbeatType {
|
|
|
Pong,
|
|
|
}
|
|
|
|
|
|
-pub struct AbstractWsMode {
|
|
|
-}
|
|
|
+pub struct AbstractWsMode {}
|
|
|
|
|
|
impl AbstractWsMode {
|
|
|
// pub fn new(write_rx: UnboundedReceiver<Message>,
|
|
|
@@ -175,7 +175,7 @@ impl AbstractWsMode {
|
|
|
trace!("---4");
|
|
|
trace!("重启...");
|
|
|
}
|
|
|
- return Ok(())
|
|
|
+ return Ok(());
|
|
|
}
|
|
|
|
|
|
// match connect_async(address_url, proxy).await {
|
|
|
@@ -222,7 +222,7 @@ impl AbstractWsMode {
|
|
|
pub async fn ping_or_pong(_bool_v1: Arc<AtomicBool>, write_tx_clone: Arc<Mutex<UnboundedSender<Message>>>, h_type: HeartbeatType, millis: u64) {
|
|
|
loop {
|
|
|
tokio::time::sleep(Duration::from_millis(millis)).await;
|
|
|
- let write_tx_clone = write_tx_clone.lock().unwrap();
|
|
|
+ let write_tx_clone = write_tx_clone.lock().await;
|
|
|
write_tx_clone.unbounded_send(
|
|
|
match h_type {
|
|
|
HeartbeatType::Ping => {
|
|
|
@@ -238,8 +238,8 @@ impl AbstractWsMode {
|
|
|
}
|
|
|
|
|
|
//发送数据
|
|
|
- pub fn send_subscribe(write_tx_clone: Arc<Mutex<UnboundedSender<Message>>>, message: Message) -> bool {
|
|
|
- let write_tx_clone = write_tx_clone.lock().unwrap();
|
|
|
+ pub async fn send_subscribe(write_tx_clone: Arc<Mutex<UnboundedSender<Message>>>, message: Message) -> bool {
|
|
|
+ let write_tx_clone = write_tx_clone.lock().await;
|
|
|
write_tx_clone.unbounded_send(message.clone()).unwrap();
|
|
|
trace!("发送指令:{:?}",message);
|
|
|
true
|