@@ -8,8 +8,8 @@ use ironrdp_svc::{ChannelFlags, SvcMessage};
88use crate :: platform:: windows:: error:: DvcPipeProxyError ;
99use crate :: windows:: { wait_any, wait_any_with_timeout, Event , MessagePipeServer , Semaphore , WindowsError } ;
1010
11- const PIPE_CONNECT_TIMEOUT : u32 = 10_000 ; // 10 seconds
12- const PIPE_WRITE_TIMEOUT : u32 = 3_000 ; // 3 seconds
11+ const PIPE_CONNECT_TIMEOUT_SECS : u32 = 10_000 ; // 10 seconds
12+ const PIPE_WRITE_TIMEOUT_SECS : u32 = 3_000 ; // 3 seconds
1313const MESSAGE_BUFFER_SIZE : usize = 64 * 1024 ; // 64 KiB
1414
1515pub ( crate ) type OnWriteDvcMessage = Box < dyn Fn ( u32 , Vec < SvcMessage > ) -> PduResult < ( ) > + Send > ;
@@ -44,9 +44,8 @@ pub(crate) fn worker_thread_func(worker_ctx: WorkerCtx) -> Result<(), DvcPipePro
4444
4545 if !connect_ctx. overlapped_connect ( ) ? {
4646 const EVENT_ID_ABORT : usize = 0 ;
47- let events = & [ abort_event. raw ( ) , connect_ctx. event ( ) . raw ( ) ] ;
48-
49- let wait_result = match wait_any_with_timeout ( events, PIPE_CONNECT_TIMEOUT ) {
47+ let events = [ abort_event. borrow ( ) , connect_ctx. borrow_event ( ) ] ;
48+ let wait_result = match wait_any_with_timeout ( events, PIPE_CONNECT_TIMEOUT_SECS ) {
5049 Ok ( idx) => idx,
5150 Err ( WindowsError :: WaitForMultipleObjectsTimeout ) => {
5251 warn ! ( %channel_name, %pipe_name, "DVC pipe proxy connection timed out" ) ;
@@ -73,22 +72,25 @@ pub(crate) fn worker_thread_func(worker_ctx: WorkerCtx) -> Result<(), DvcPipePro
7372 const EVENT_ID_ABORT : usize = 0 ;
7473 const EVENT_ID_READ : usize = 1 ;
7574 const EVENT_ID_WRITE_MPSC : usize = 2 ;
76- let events = & [ abort_event. raw ( ) , read_ctx. event ( ) . raw ( ) , to_pipe_semaphore. raw ( ) ] ;
7775
7876 read_ctx. overlapped_read ( ) ?;
7977
8078 info ! ( %channel_name, %pipe_name, "DVC pipe proxy IO loop started" ) ;
8179
8280 loop {
81+ let events = [
82+ abort_event. borrow ( ) ,
83+ read_ctx. borrow_event ( ) ,
84+ to_pipe_semaphore. borrow ( ) ,
85+ ] ;
8386 let wait_result = wait_any ( events) ?;
8487
85- // abort event
8688 if wait_result == EVENT_ID_ABORT {
8789 info ! ( %channel_name, %pipe_name, "DVC pipe proxy connection has been aborted" ) ;
8890 return Ok ( ( ) ) ;
8991 }
9092
91- // read from pipe
93+ // Read end of pipe is ready, forward received data to DVC.
9294 if wait_result == EVENT_ID_READ {
9395 let read_result = read_ctx. get_result ( ) ?. to_vec ( ) ;
9496
@@ -107,12 +109,12 @@ pub(crate) fn worker_thread_func(worker_ctx: WorkerCtx) -> Result<(), DvcPipePro
107109 }
108110 }
109111
110- // Queue the read operation again
112+ // Queue the read operation again.
111113 read_ctx. overlapped_read ( ) ?;
112114 continue ;
113115 }
114116
115- // read from mpsc and write to pipe
117+ // DVC data received, forward it to the pipe.
116118 if wait_result == EVENT_ID_WRITE_MPSC {
117119 let payload = to_pipe_rx. recv ( ) . map_err ( |_| DvcPipeProxyError :: MpscIo ) ?;
118120
@@ -125,25 +127,22 @@ pub(crate) fn worker_thread_func(worker_ctx: WorkerCtx) -> Result<(), DvcPipePro
125127
126128 trace ! ( %channel_name, %pipe_name, "DVC proxy write {} bytes to pipe," , payload_len) ;
127129
128- // write to pipe
129130 let mut overlapped_write = pipe. prepare_write_overlapped ( payload) ?;
130131
131- let events = & [ abort_event. raw ( ) , overlapped_write. event ( ) . raw ( ) ] ;
132-
133132 overlapped_write. overlapped_write ( ) ?;
134- let wait_result = wait_any_with_timeout ( events, PIPE_WRITE_TIMEOUT ) ?;
135133
136- // abort event
134+ let events = [ abort_event. borrow ( ) , overlapped_write. borrow_event ( ) ] ;
135+ let wait_result = wait_any_with_timeout ( events, PIPE_WRITE_TIMEOUT_SECS ) ?;
136+
137137 if wait_result == EVENT_ID_ABORT {
138138 info ! ( %channel_name, %pipe_name, "DVC pipe proxy write aborted" ) ;
139139 return Ok ( ( ) ) ;
140140 }
141141
142- // write to pipe
143142 let bytes_written = overlapped_write. get_result ( ) ?;
144143
145144 if bytes_written as usize != payload_len {
146- // Message-based pipe write failed
145+ // Message-based pipe write failed.
147146 return Err ( DvcPipeProxyError :: DvcIncompleteWrite ) ;
148147 }
149148
0 commit comments