Skip to content

Commit

Permalink
Reorder NamedPipe fields
Browse files Browse the repository at this point in the history
Moving the Overlapped fields to the start to make it easier to determine
the offsets and hopefully incur less breakage once external fields
change size.

Note that the Overlapped fields internally uses miow::Overlapped, which
in turn is a OVERLAPPED struct as found in the winapi crate and has a
stable layout (as defined by the Windows API).
  • Loading branch information
Thomasdezeeuw committed May 13, 2021
1 parent db0d74c commit 9e13732
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/sys/windows/named_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,19 @@ pub struct NamedPipe {
/// constants depend on it, see the `offset_constants` test.
#[repr(C)]
struct Inner {
handle: pipe::NamedPipe,

connect: Overlapped,
connecting: AtomicBool,

read: Overlapped,
write: Overlapped,

handle: pipe::NamedPipe,
connecting: AtomicBool,
io: Mutex<Io>,

pool: Mutex<BufferPool>,
}

/// Offsets from a pointer to `Inner` to the `connect`, `read` and `write`
/// fields.
const CONNECT_OFFSET: usize = size_of::<pipe::NamedPipe>(); // `handle` field.
const READ_OFFSET: usize = CONNECT_OFFSET + size_of::<Overlapped>() + size_of::<usize>(); // `connect`, `connecting` (`bool` + padding) fields.
const CONNECT_OFFSET: usize = 0;
const READ_OFFSET: usize = CONNECT_OFFSET + size_of::<Overlapped>(); // `connect` fields.
const WRITE_OFFSET: usize = READ_OFFSET + size_of::<Overlapped>(); // `read` fields.

#[test]
Expand Down

0 comments on commit 9e13732

Please sign in to comment.