Skip to content

Commit 2422fde

Browse files
author
bors-servo
authored
Auto merge of #99 - jrmuizel:remove-retry, r=pcwalton
Remove mach_msg retry loop. The idiomatic solution to dealing with the trailer bytes is to just add the maximum trailer size to msg size returned by the kernel.
2 parents 3852245 + 3d7d279 commit 2422fde

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

src/platform/macos/mod.rs

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -573,33 +573,29 @@ fn select(port: mach_port_t, blocking_mode: BlockingMode)
573573
timeout,
574574
MACH_PORT_NULL) {
575575
MACH_RCV_TOO_LARGE => {
576-
// Do a loop. There's no way I know of to figure out precisely in advance how big
577-
// the message actually is!
578-
let mut extra_size = 8;
579-
loop {
580-
let actual_size = (*message).header.msgh_size + extra_size;
581-
allocated_buffer = Some(libc::malloc(actual_size as size_t));
582-
setup_receive_buffer(slice::from_raw_parts_mut(
583-
allocated_buffer.unwrap() as *mut u8,
584-
actual_size as usize),
585-
port);
586-
message = allocated_buffer.unwrap() as *mut Message;
587-
match mach_sys::mach_msg(message as *mut _,
588-
flags,
589-
0,
590-
actual_size,
591-
port,
592-
timeout,
593-
MACH_PORT_NULL) {
594-
MACH_MSG_SUCCESS => break,
595-
MACH_RCV_TOO_LARGE => {
596-
libc::free(allocated_buffer.unwrap() as *mut _);
597-
extra_size *= 2;
598-
}
599-
os_result => {
600-
libc::free(allocated_buffer.unwrap() as *mut _);
601-
return Err(MachError(os_result))
602-
}
576+
// the actual size gets written into msgh_size by the kernel
577+
let max_trailer_size = mem::size_of::<mach_sys::mach_msg_max_trailer_t>() as mach_sys::mach_msg_size_t;
578+
let actual_size = (*message).header.msgh_size + max_trailer_size;
579+
allocated_buffer = Some(libc::malloc(actual_size as size_t));
580+
setup_receive_buffer(slice::from_raw_parts_mut(
581+
allocated_buffer.unwrap() as *mut u8,
582+
actual_size as usize),
583+
port);
584+
message = allocated_buffer.unwrap() as *mut Message;
585+
match mach_sys::mach_msg(message as *mut _,
586+
flags,
587+
0,
588+
actual_size,
589+
port,
590+
timeout,
591+
MACH_PORT_NULL) {
592+
MACH_MSG_SUCCESS => {},
593+
MACH_RCV_TOO_LARGE => {
594+
panic!("message was bigger than we were told");
595+
}
596+
os_result => {
597+
libc::free(allocated_buffer.unwrap() as *mut _);
598+
return Err(MachError(os_result))
603599
}
604600
}
605601
}

0 commit comments

Comments
 (0)