@@ -45,10 +45,16 @@ struct Args {
45
45
ttyname : Option < String > ,
46
46
}
47
47
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
+
48
55
/// 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 ) ) ) ;
52
58
53
59
/// The size of the buffer for control message fields like l_name, r_name, and r_tty in CtlMsg.
54
60
const BUFFER_SIZE : usize = 12 ;
@@ -947,7 +953,13 @@ fn handle_new_invitation(
947
953
948
954
let clone_socket = Arc :: clone ( & socket) ;
949
955
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
+
951
963
// Start listening for incoming TCP connections.
952
964
for stream in listener. incoming ( ) {
953
965
match stream {
@@ -1613,12 +1625,10 @@ pub fn handle_signals(signal_code: libc::c_int) {
1613
1625
eprintln ! ( "Connection closed, exiting..." ) ;
1614
1626
1615
1627
// 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 ( ) {
1619
1629
// 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 ) ;
1622
1632
}
1623
1633
1624
1634
// Exit the process with a code indicating the signal received
0 commit comments