Skip to content

Commit

Permalink
wayland-commons: avoid empty sendmsg on flush
Browse files Browse the repository at this point in the history
If there is nothing to send, there's no point actually making the system call.
The list of FDs is not checked because sending FDs without also sending data is
not permitted anyway.

This also updates tests to detect errors on reads (not writes), which is where
a real client would expect to detect them.  The native client requires two
reads because the first one will just read the protocol error message.
  • Loading branch information
danieldg authored and vberger committed Feb 22, 2021
1 parent f8b7a9e commit 1d3a01d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/protocol_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ fn client_wrong_id() {

server.answer();

// server should have killed us due to the error
assert_eq!(socket.flush(), Err(nix::Error::Sys(nix::errno::Errno::EPIPE)));
// server should have killed us due to the error, but it might send us that error first
let err = socket.fill_incoming_buffers().and_then(|_| socket.fill_incoming_buffers());
assert_eq!(err, Err(nix::Error::Sys(nix::errno::Errno::EPIPE)));
}

#[test]
Expand All @@ -62,8 +63,9 @@ fn client_wrong_opcode() {

server.answer();

// server should have killed us due to the error
assert_eq!(socket.flush(), Err(nix::Error::Sys(nix::errno::Errno::EPIPE)));
// server should have killed us due to the error, but it might send us that error first
let err = socket.fill_incoming_buffers().and_then(|_| socket.fill_incoming_buffers());
assert_eq!(err, Err(nix::Error::Sys(nix::errno::Errno::EPIPE)));
}

#[test]
Expand All @@ -86,8 +88,9 @@ fn client_wrong_sender() {

server.answer();

// server should have killed us due to the error
assert_eq!(socket.flush(), Err(nix::Error::Sys(nix::errno::Errno::EPIPE)));
// server should have killed us due to the error, but it might send us that error first
let err = socket.fill_incoming_buffers().and_then(|_| socket.fill_incoming_buffers());
assert_eq!(err, Err(nix::Error::Sys(nix::errno::Errno::EPIPE)));
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions wayland-commons/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ impl BufferedSocket {
pub fn flush(&mut self) -> NixResult<()> {
{
let words = self.out_data.get_contents();
if words.is_empty() {
return Ok(());
}
let bytes = unsafe {
::std::slice::from_raw_parts(words.as_ptr() as *const u8, words.len() * 4)
};
Expand Down

0 comments on commit 1d3a01d

Please sign in to comment.