@@ -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 ;
@@ -947,7 +953,13 @@ fn handle_new_invitation(
947953
948954 let clone_socket = Arc :: clone ( & socket) ;
949955
950- * DELETE_INVITATIONS . lock ( ) . unwrap ( ) = Some ( ( msg_bytes1, msg_bytes2, clone_socket, talkd_addr) ) ;
956+ * DELETE_INVITATIONS . lock ( ) . unwrap ( ) = Some ( State {
957+ msg_bytes1,
958+ msg_bytes2,
959+ socket : clone_socket,
960+ talkd_addr,
961+ } ) ;
962+
951963 // Start listening for incoming TCP connections.
952964 for stream in listener. incoming ( ) {
953965 match stream {
@@ -1613,12 +1625,10 @@ pub fn handle_signals(signal_code: libc::c_int) {
16131625 eprintln ! ( "Connection closed, exiting..." ) ;
16141626
16151627 // Lock the DELETE_INVITATIONS mutex and check for an existing invitation
1616- if let Some ( ( msg_bytes1, msg_bytes2, socket, talkd_addr) ) =
1617- DELETE_INVITATIONS . lock ( ) . unwrap ( ) . as_ref ( )
1618- {
1628+ if let Some ( state) = DELETE_INVITATIONS . lock ( ) . unwrap ( ) . as_ref ( ) {
16191629 // Handle the deletion of invitations
1620- handle_delete_invitations ( socket, msg_bytes1, talkd_addr) ;
1621- handle_delete_invitations ( socket, msg_bytes2, talkd_addr) ;
1630+ handle_delete_invitations ( & state . socket , & state . msg_bytes1 , & state . talkd_addr ) ;
1631+ handle_delete_invitations ( & state . socket , & state . msg_bytes2 , & state . talkd_addr ) ;
16221632 }
16231633
16241634 // Exit the process with a code indicating the signal received
0 commit comments