Skip to content

Commit 6031139

Browse files
committed
windows: Introduce MessageReader.get_raw_handle() debug helper
Add a (conditional) helper method for obtaining the raw handle of the reader -- which is often needed for the `win32_trace` invocations -- to abstract the internal structure of this type, thus facilitating further refactoring. An alternate approach would be overriding the `Debug` trait on `MessageReader`, to just print the raw handle value. That would provide better encapsulation; however, it would also preclude the possibility of easily printing all the constituents of the structure during debugging... (Or we could leave `Debug` alone, and instead implement it as `Display` -- but that feels like an abuse of the `Display` facility... Not sure what to think about that.)
1 parent ab2dced commit 6031139

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/platform/windows/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,14 @@ impl MessageReader {
820820

821821
Ok(mem::replace(&mut self.read_buf, vec![]))
822822
}
823+
824+
/// Get raw handle of the receive port.
825+
///
826+
/// This is only for debug tracing purposes, and must not be used for anything else.
827+
#[cfg(feature = "win32-trace")]
828+
fn get_raw_handle(&self) -> HANDLE {
829+
self.handle.as_raw()
830+
}
823831
}
824832

825833
#[derive(Clone, Copy, Debug)]
@@ -1329,13 +1337,13 @@ impl OsIpcReceiverSet {
13291337

13301338
match reader.add_to_iocp(&self.iocp, entry_id) {
13311339
Ok(()) => {
1332-
win32_trace!("[# {:?}] ReceiverSet add {:?}, id {}", self.iocp.as_raw(), reader.handle.as_raw(), entry_id);
1340+
win32_trace!("[# {:?}] ReceiverSet add {:?}, id {}", self.iocp.as_raw(), reader.get_raw_handle(), entry_id);
13331341
self.readers.push(reader);
13341342
}
13351343
Err(WinError::ChannelClosed) => {
13361344
// If the sender has already been closed, we need to stash this information,
13371345
// so we can report the corresponding event in the next `select()` call.
1338-
win32_trace!("[# {:?}] ReceiverSet add {:?} (closed), id {}", self.iocp.as_raw(), reader.handle.as_raw(), entry_id);
1346+
win32_trace!("[# {:?}] ReceiverSet add {:?} (closed), id {}", self.iocp.as_raw(), reader.get_raw_handle(), entry_id);
13391347
self.closed_readers.push(entry_id);
13401348
}
13411349
Err(err) => return Err(err),
@@ -1404,7 +1412,7 @@ impl OsIpcReceiverSet {
14041412
// if we can successfully initiate another async read operation.
14051413
let mut reader = self.readers.swap_remove(reader_index);
14061414

1407-
win32_trace!("[# {:?}] result for receiver {:?}", self.iocp.as_raw(), reader.handle.as_raw());
1415+
win32_trace!("[# {:?}] result for receiver {:?}", self.iocp.as_raw(), reader.get_raw_handle());
14081416

14091417
// tell it about the completed IO op
14101418
let result = reader.notify_completion(io_result);
@@ -1440,10 +1448,10 @@ impl OsIpcReceiverSet {
14401448
if !closed {
14411449
// Drain as many messages as we can.
14421450
while let Some((data, channels, shmems)) = try!(reader.get_message()) {
1443-
win32_trace!("[# {:?}] receiver {:?} ({}) got a message", self.iocp.as_raw(), reader.handle.as_raw(), reader.entry_id.unwrap());
1451+
win32_trace!("[# {:?}] receiver {:?} ({}) got a message", self.iocp.as_raw(), reader.get_raw_handle(), reader.entry_id.unwrap());
14441452
selection_results.push(OsIpcSelectionResult::DataReceived(reader.entry_id.unwrap(), data, channels, shmems));
14451453
}
1446-
win32_trace!("[# {:?}] receiver {:?} ({}) -- no message", self.iocp.as_raw(), reader.handle.as_raw(), reader.entry_id.unwrap());
1454+
win32_trace!("[# {:?}] receiver {:?} ({}) -- no message", self.iocp.as_raw(), reader.get_raw_handle(), reader.entry_id.unwrap());
14471455

14481456
// Now that we are done frobbing the buffer,
14491457
// we can safely initiate the next async read operation.
@@ -1467,7 +1475,7 @@ impl OsIpcReceiverSet {
14671475
// or while trying to re-initiate an async read after receiving data --
14681476
// add an event to this effect to the result list.
14691477
if closed {
1470-
win32_trace!("[# {:?}] receiver {:?} ({}) -- now closed!", self.iocp.as_raw(), reader.handle.as_raw(), reader.entry_id.unwrap());
1478+
win32_trace!("[# {:?}] receiver {:?} ({}) -- now closed!", self.iocp.as_raw(), reader.get_raw_handle(), reader.entry_id.unwrap());
14711479
selection_results.push(OsIpcSelectionResult::ChannelClosed(reader.entry_id.unwrap()));
14721480
}
14731481
}

0 commit comments

Comments
 (0)