@@ -66,57 +66,61 @@ pub async fn start(arc_map: Arc<std::sync::Mutex<HashMap<IpAddr,super::Target>>>
66
66
let peer = stream. peer_addr ( ) . expect ( "connected streams should have a peer address" ) ;
67
67
//tokio::spawn(accept_connection(arc_map.clone(), stream));
68
68
//tokio::spawn(accept_connection(arc_map.clone(), peer, stream));
69
- let handle = tokio:: spawn ( handle_connection ( arc_map. clone ( ) , peer, stream) ) ;
70
- //let _ = handle.await.unwrap();
69
+
70
+ //tokio::spawn(handle_connection(arc_map.clone(), peer, stream));
71
+ tokio:: spawn ( handle_connection ( arc_map. clone ( ) , peer, stream) ) ;
72
+
73
+ //let handle = tokio::spawn(handle_connection(arc_map, peer, stream));
71
74
72
75
}
73
76
74
77
Ok ( ( ) )
75
78
}
76
79
77
- async fn accept_connection ( arc_map : Arc < std:: sync:: Mutex < HashMap < IpAddr , super :: Target > > > , peer : SocketAddr , stream : TcpStream )
78
- -> Result < ( ) > {
79
- /*
80
- let addr = stream.peer_addr().expect("connected streams should have a peer address");
81
- //info!("Peer address: {}", addr);
82
-
83
- let ws_stream = tokio_tungstenite::accept_async(stream)
84
- .await
85
- .expect("Error during the websocket handshake occurred");
86
-
87
- //info!("New WebSocket connection: {}", addr);
88
-
89
- let (write, read) = ws_stream.split();
90
- read.forward(write).await.expect("Failed to forward message");
91
- */
92
80
93
-
94
- if let Err ( e) = handle_connection ( arc_map, peer, stream) . await {
95
- match e {
96
- Error :: ConnectionClosed | Error :: Protocol ( _) | Error :: Utf8 => ( ) ,
97
- err => error ! ( "Error processing connection: {}" , err) ,
98
- }
99
- }
100
- Ok ( ( ) )
81
+ //async fn accept_connection(arc_map: Arc<std::sync::Mutex<HashMap<IpAddr,super::Target>>>,peer: SocketAddr,stream: TcpStream)
82
+ // -> Result<()> {
83
+ // /*
84
+ // let addr = stream.peer_addr().expect("connected streams should have a peer address");
85
+ // //info!("Peer address: {}", addr);
86
+ //
87
+ // let ws_stream = tokio_tungstenite::accept_async(stream)
88
+ // .await
89
+ // .expect("Error during the websocket handshake occurred");
90
+ //
91
+ // //info!("New WebSocket connection: {}", addr);
92
+ //
93
+ // let (write, read) = ws_stream.split();
94
+ // read.forward(write).await.expect("Failed to forward message");
95
+ //*/
96
+ //
97
+ //
98
+ //// if let Err(e) = handle_connection(arc_map, peer, stream).await {
99
+ //// match e {
100
+ //// Error::ConnectionClosed | Error::Protocol(_) | Error::Utf8 => (),
101
+ //// err => error!("Error processing connection: {}", err),
102
+ //// }
103
+ //// }
104
+ //// Ok(())
105
+ //
106
+ ///*
107
+ // let ipaddr = IpAddr::V4(Ipv4Addr::new(10, 1, 0, 2));
108
+ // let mut map = arc_map.lock().unwrap();
109
+ // if map.contains_key(&ipaddr) {
110
+ // match map.get(&ipaddr) {
111
+ // Some(target) => { //&target.tx,
112
+ // println!(" is match.");
113
+ // },
114
+ // None => {
115
+ // println!(" is unreviewed.");
116
+ // return;
117
+ // }
118
+ // }
119
+ // }
120
+ //*/
121
+ //}
101
122
102
123
/*
103
- let ipaddr = IpAddr::V4(Ipv4Addr::new(10, 1, 0, 2));
104
- let mut map = arc_map.lock().unwrap();
105
- if map.contains_key(&ipaddr) {
106
- match map.get(&ipaddr) {
107
- Some(target) => { //&target.tx,
108
- println!(" is match.");
109
- },
110
- None => {
111
- println!(" is unreviewed.");
112
- return;
113
- }
114
- }
115
- }
116
- */
117
- }
118
-
119
-
120
124
//async fn parser(arc_map: &Arc<std::sync::Mutex<HashMap<IpAddr,super::Target>>>, msg :&Message) -> Result<()> {
121
125
async fn parser(arc_map: &Arc<std::sync::Mutex<HashMap<IpAddr,super::Target>>>, msg :&Message) {
122
126
@@ -153,6 +157,7 @@ async fn parser(arc_map: &Arc<std::sync::Mutex<HashMap<IpAddr,super::Target>>>,
153
157
//Ok(())
154
158
155
159
}
160
+ */
156
161
/*
157
162
async fn parser(arc_map: &Arc<std::sync::Mutex<HashMap<IpAddr,super::Target>>>, msg :&Message) -> Result<()> {
158
163
@@ -205,34 +210,41 @@ async fn handle_connection(arc_map: Arc<std::sync::Mutex<HashMap<IpAddr,super::T
205
210
if msg. is_text( ) ||msg. is_binary( ) {
206
211
207
212
// parser(&arc_map, &msg).await;
213
+
208
214
ws_sender. send( msg) . await ?;
209
215
210
- let ipaddr = IpAddr :: V4 ( Ipv4Addr :: new( 10 , 1 , 0 , 2 ) ) ;
211
- //let map = arc_map.lock().unwrap();
212
- let map_lock = Arc :: clone( & arc_map) ;
213
- let map = map_lock. lock( ) . unwrap( ) ;
214
- let rtx_ = if map. contains_key( & ipaddr) {
215
- match map. get( & ipaddr) {
216
- Some ( target) => {
217
- println!( "map ok " ) ;
218
- Some ( target. tx. clone( ) )
219
- } ,
220
- None => {
221
- println!( "map ng " ) ;
222
- None
223
- }
224
- }
225
- } else {
226
- None
227
- } ;
216
+ let rtx_ = {
217
+ let ipaddr = IpAddr :: V4 ( Ipv4Addr :: new( 10 , 1 , 0 , 2 ) ) ;
218
+
219
+ let map = arc_map. lock( ) . unwrap( ) ;
220
+ //let map_lock = Arc::clone(&arc_map);
221
+ //let map = map_lock.lock().unwrap();
222
+ let tmp_tx = if map. contains_key( & ipaddr) {
223
+ match map. get( & ipaddr) {
224
+ Some ( target) => {
225
+ println!( "map ok " ) ;
226
+ //Some(target.tx.clone())
227
+ Some ( target. tx. clone( ) )
228
+ } ,
229
+ None => {
230
+ println!( "map ng " ) ;
231
+ None
232
+ }
233
+ }
234
+ } else {
235
+ None
236
+ } ;
237
+ tmp_tx
238
+ } ; // arc_map.locked drop ....
228
239
229
240
match rtx_ {
230
241
231
242
Some ( tx) => {
232
243
let cmd = super :: Command :: Cmd {
233
- key: "*command" . to_string( ) ,
244
+ key: "*command* " . to_string( ) ,
234
245
} ;
235
- //tx.send(cmd).await.unwrap();
246
+ tx. send( cmd) . await . unwrap( ) ;
247
+ println!( "tx send ok " ) ;
236
248
237
249
} ,
238
250
None => {
0 commit comments