@@ -25,6 +25,7 @@ use ratatui::{Terminal, backend::Backend};
25
25
use semver:: Version ;
26
26
use system_statistics_screen:: { SystemStatisticsScreen , SystemStatisticsScreenMessage } ;
27
27
use tokio:: sync:: Mutex ;
28
+ use tokio_util:: sync:: CancellationToken ;
28
29
use tui:: { Tui , print_exit_screen} ;
29
30
30
31
use crate :: bbs:: await_securewebsocket_connections;
@@ -123,7 +124,8 @@ async fn start_icy_board(arguments: &Cli, file: PathBuf) -> Res<()> {
123
124
restore_terminal ( ) ?;
124
125
return Ok ( ( ) ) ;
125
126
}
126
- start_connections ( & bbs, & board) . await ;
127
+ let mut connection_token = CancellationToken :: new ( ) ;
128
+ start_connections ( & bbs, & board, connection_token. clone ( ) ) . await ;
127
129
let mut app = CallWaitScreen :: new ( & board) . await ?;
128
130
let mut terminal = init_terminal ( ) ?;
129
131
loop {
@@ -139,7 +141,9 @@ async fn start_icy_board(arguments: &Cli, file: PathBuf) -> Res<()> {
139
141
bbs = Arc :: new ( Mutex :: new ( BBS :: new ( icy_board. config . board . num_nodes as usize ) ) ) ;
140
142
board = Arc :: new ( tokio:: sync:: Mutex :: new ( icy_board) ) ;
141
143
app = CallWaitScreen :: new ( & board) . await ?;
142
- start_connections ( & bbs, & board) . await ;
144
+ connection_token. cancel ( ) ;
145
+ connection_token = CancellationToken :: new ( ) ;
146
+ start_connections ( & bbs, & board, connection_token. clone ( ) ) . await ;
143
147
continue ;
144
148
}
145
149
}
@@ -167,30 +171,17 @@ async fn start_icy_board(arguments: &Cli, file: PathBuf) -> Res<()> {
167
171
}
168
172
}
169
173
170
- static mut TELENET_RECEIVER : Option < tokio:: sync:: oneshot:: Receiver < bool > > = None ;
171
- static mut SSH_RECEIVER : Option < tokio:: sync:: oneshot:: Receiver < bool > > = None ;
172
- static mut SWEBSOCKET_RECEIVER : Option < tokio:: sync:: oneshot:: Receiver < bool > > = None ;
173
-
174
- async fn start_connections ( bbs : & Arc < Mutex < BBS > > , board : & Arc < Mutex < IcyBoard > > ) {
174
+ async fn start_connections ( bbs : & Arc < Mutex < BBS > > , board : & Arc < Mutex < IcyBoard > > , token : CancellationToken ) {
175
175
let telnet_connection: icy_board_engine:: icy_board:: login_server:: Telnet = board. lock ( ) . await . config . login_server . telnet . clone ( ) ;
176
176
if telnet_connection. is_enabled {
177
177
let bbs = bbs. clone ( ) ;
178
178
let board: Arc < Mutex < IcyBoard > > = board. clone ( ) ;
179
- let ( mut tx1, rx1) = tokio:: sync:: oneshot:: channel :: < bool > ( ) ;
180
- unsafe {
181
- #[ allow( static_mut_refs) ]
182
- if let Some ( mut rx) = TELENET_RECEIVER . take ( ) {
183
- rx. close ( ) ;
184
- }
185
-
186
- TELENET_RECEIVER = Some ( rx1) ;
187
- }
179
+ let token = token. clone ( ) ;
188
180
tokio:: spawn ( async move {
189
181
tokio:: select! {
190
182
_ = await_telnet_connections( telnet_connection, board, bbs) => {
191
183
} ,
192
- _ = tx1. closed( ) => {
193
- log:: info!( "telnet connection closed" ) ;
184
+ _ = token. cancelled( ) => {
194
185
}
195
186
}
196
187
} ) ;
@@ -200,23 +191,12 @@ async fn start_connections(bbs: &Arc<Mutex<BBS>>, board: &Arc<Mutex<IcyBoard>>)
200
191
if ssh_connection. is_enabled {
201
192
let bbs: Arc < Mutex < BBS > > = bbs. clone ( ) ;
202
193
let board = board. clone ( ) ;
203
-
204
- let ( mut tx1, rx1) = tokio:: sync:: oneshot:: channel :: < bool > ( ) ;
205
- unsafe {
206
- #[ allow( static_mut_refs) ]
207
- if let Some ( mut rx) = SSH_RECEIVER . take ( ) {
208
- rx. close ( ) ;
209
- }
210
-
211
- SSH_RECEIVER = Some ( rx1) ;
212
- }
213
-
194
+ let token = token. clone ( ) ;
214
195
tokio:: spawn ( async move {
215
196
tokio:: select! {
216
197
_ = bbs:: ssh:: await_ssh_connections( ssh_connection, board, bbs) => {
217
198
} ,
218
- _ = tx1. closed( ) => {
219
- log:: info!( "telnet connection closed" ) ;
199
+ _ = token. cancelled( ) => {
220
200
}
221
201
}
222
202
} ) ;
@@ -239,23 +219,12 @@ async fn start_connections(bbs: &Arc<Mutex<BBS>>, board: &Arc<Mutex<IcyBoard>>)
239
219
if secure_websocket_connection. is_enabled {
240
220
let bbs = bbs. clone ( ) ;
241
221
let board = board. clone ( ) ;
242
-
243
- let ( mut tx1, rx1) = tokio:: sync:: oneshot:: channel :: < bool > ( ) ;
244
- unsafe {
245
- #[ allow( static_mut_refs) ]
246
- if let Some ( mut rx) = SWEBSOCKET_RECEIVER . take ( ) {
247
- rx. close ( ) ;
248
- }
249
-
250
- SWEBSOCKET_RECEIVER = Some ( rx1) ;
251
- }
252
-
222
+ let token = token. clone ( ) ;
253
223
tokio:: spawn ( async move {
254
224
tokio:: select! {
255
225
_ = await_securewebsocket_connections( secure_websocket_connection, board, bbs) => {
256
226
} ,
257
- _ = tx1. closed( ) => {
258
- log:: info!( "telnet connection closed" ) ;
227
+ _ = token. cancelled( ) => {
259
228
}
260
229
}
261
230
} ) ;
0 commit comments