@@ -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 ;
@@ -954,7 +960,13 @@ fn handle_new_invitation(
954
960
955
961
let clone_socket = Arc :: clone ( & socket) ;
956
962
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
+
958
970
// Start listening for incoming TCP connections.
959
971
for stream in listener. incoming ( ) {
960
972
match stream {
@@ -1620,12 +1632,10 @@ pub fn handle_signals(signal_code: libc::c_int) {
1620
1632
eprintln ! ( "Connection closed, exiting..." ) ;
1621
1633
1622
1634
// 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 ( ) {
1626
1636
// 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 ) ;
1629
1639
}
1630
1640
1631
1641
// Exit the process with a code indicating the signal received
0 commit comments