@@ -45,10 +45,16 @@ struct Args {
4545 ttyname : Option < String > ,
4646}
4747
48+ pub struct State {
49+ pub msg_bytes1 : Vec < u8 > ,
50+ pub msg_bytes2 : Vec < u8 > ,
51+ pub socket : Arc < UdpSocket > ,
52+ pub talkd_addr : SocketAddr ,
53+ }
54+
4855/// A static variable to hold the state of delete invitations on SIGINT signal.
49- static DELETE_INVITATIONS : LazyLock <
50- Arc < Mutex < Option < ( Vec < u8 > , Vec < u8 > , Arc < UdpSocket > , SocketAddr ) > > > ,
51- > = LazyLock :: new ( || Arc :: new ( Mutex :: new ( None ) ) ) ;
56+ static DELETE_INVITATIONS : LazyLock < Arc < Mutex < Option < State > > > > =
57+ LazyLock :: new ( || Arc :: new ( Mutex :: new ( None ) ) ) ;
5258
5359/// The size of the buffer for control message fields like l_name, r_name, and r_tty in CtlMsg.
5460const BUFFER_SIZE : usize = 12 ;
@@ -954,7 +960,13 @@ fn handle_new_invitation(
954960
955961 let clone_socket = Arc :: clone ( & socket) ;
956962
957- * DELETE_INVITATIONS . lock ( ) . unwrap ( ) = Some ( ( msg_bytes1, msg_bytes2, clone_socket, talkd_addr) ) ;
963+ * DELETE_INVITATIONS . lock ( ) . unwrap ( ) = Some ( State {
964+ msg_bytes1,
965+ msg_bytes2,
966+ socket : clone_socket,
967+ talkd_addr,
968+ } ) ;
969+
958970 // Start listening for incoming TCP connections.
959971 for stream in listener. incoming ( ) {
960972 match stream {
@@ -1620,12 +1632,10 @@ pub fn handle_signals(signal_code: libc::c_int) {
16201632 eprintln ! ( "Connection closed, exiting..." ) ;
16211633
16221634 // Lock the DELETE_INVITATIONS mutex and check for an existing invitation
1623- if let Some ( ( msg_bytes1, msg_bytes2, socket, talkd_addr) ) =
1624- DELETE_INVITATIONS . lock ( ) . unwrap ( ) . as_ref ( )
1625- {
1635+ if let Some ( state) = DELETE_INVITATIONS . lock ( ) . unwrap ( ) . as_ref ( ) {
16261636 // Handle the deletion of invitations
1627- handle_delete_invitations ( socket, msg_bytes1, talkd_addr) ;
1628- handle_delete_invitations ( socket, msg_bytes2, talkd_addr) ;
1637+ handle_delete_invitations ( & state . socket , & state . msg_bytes1 , & state . talkd_addr ) ;
1638+ handle_delete_invitations ( & state . socket , & state . msg_bytes2 , & state . talkd_addr ) ;
16291639 }
16301640
16311641 // Exit the process with a code indicating the signal received
0 commit comments