Skip to content

Commit 9a67245

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 44f262c commit 9a67245

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/platform/windows/mod.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,14 @@ impl MessageReader {
814814

815815
Ok(mem::replace(&mut self.read_buf, vec![]))
816816
}
817+
818+
/// Get raw handle of the receive port.
819+
///
820+
/// This is only for debug tracing purposes, and must not be used for anything else.
821+
#[cfg(feature = "win32-trace")]
822+
fn get_raw_handle(&self) -> HANDLE {
823+
self.handle.as_raw()
824+
}
817825
}
818826

819827
#[derive(Clone, Copy, Debug)]
@@ -1323,13 +1331,13 @@ impl OsIpcReceiverSet {
13231331

13241332
match reader.add_to_iocp(&self.iocp, entry_id) {
13251333
Ok(()) => {
1326-
win32_trace!("[# {:?}] ReceiverSet add {:?}, id {}", self.iocp.as_raw(), reader.handle.as_raw(), entry_id);
1334+
win32_trace!("[# {:?}] ReceiverSet add {:?}, id {}", self.iocp.as_raw(), reader.get_raw_handle(), entry_id);
13271335
self.readers.push(reader);
13281336
}
13291337
Err(WinError::ChannelClosed) => {
13301338
// If the sender has already been closed, we need to stash this information,
13311339
// so we can report the corresponding event in the next `select()` call.
1332-
win32_trace!("[# {:?}] ReceiverSet add {:?} (closed), id {}", self.iocp.as_raw(), reader.handle.as_raw(), entry_id);
1340+
win32_trace!("[# {:?}] ReceiverSet add {:?} (closed), id {}", self.iocp.as_raw(), reader.get_raw_handle(), entry_id);
13331341
self.closed_readers.push(entry_id);
13341342
}
13351343
Err(err) => return Err(err),
@@ -1398,7 +1406,7 @@ impl OsIpcReceiverSet {
13981406
// if we can successfully initiate another async read operation.
13991407
let mut reader = self.readers.swap_remove(reader_index);
14001408

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

14031411
// tell it about the completed IO op
14041412
let result = reader.notify_completion(io_result);
@@ -1434,10 +1442,10 @@ impl OsIpcReceiverSet {
14341442
if !closed {
14351443
// Drain as many messages as we can.
14361444
while let Some((data, channels, shmems)) = try!(reader.get_message()) {
1437-
win32_trace!("[# {:?}] receiver {:?} ({}) got a message", self.iocp.as_raw(), reader.handle.as_raw(), reader.entry_id.unwrap());
1445+
win32_trace!("[# {:?}] receiver {:?} ({}) got a message", self.iocp.as_raw(), reader.get_raw_handle(), reader.entry_id.unwrap());
14381446
selection_results.push(OsIpcSelectionResult::DataReceived(reader.entry_id.unwrap(), data, channels, shmems));
14391447
}
1440-
win32_trace!("[# {:?}] receiver {:?} ({}) -- no message", self.iocp.as_raw(), reader.handle.as_raw(), reader.entry_id.unwrap());
1448+
win32_trace!("[# {:?}] receiver {:?} ({}) -- no message", self.iocp.as_raw(), reader.get_raw_handle(), reader.entry_id.unwrap());
14411449

14421450
// Now that we are done frobbing the buffer,
14431451
// we can safely initiate the next async read operation.
@@ -1461,7 +1469,7 @@ impl OsIpcReceiverSet {
14611469
// or while trying to re-initiate an async read after receiving data --
14621470
// add an event to this effect to the result list.
14631471
if closed {
1464-
win32_trace!("[# {:?}] receiver {:?} ({}) -- now closed!", self.iocp.as_raw(), reader.handle.as_raw(), reader.entry_id.unwrap());
1472+
win32_trace!("[# {:?}] receiver {:?} ({}) -- now closed!", self.iocp.as_raw(), reader.get_raw_handle(), reader.entry_id.unwrap());
14651473
selection_results.push(OsIpcSelectionResult::ChannelClosed(reader.entry_id.unwrap()));
14661474
}
14671475
}

0 commit comments

Comments
 (0)