Skip to content

Commit

Permalink
🚑️ zb: Fix 0 byte transfer on FreeBSD for non-UDS sockets
Browse files Browse the repository at this point in the history
We were assuming that SCM_CREDS is available for all sockets on FreeBSD.
  • Loading branch information
zeenix committed May 1, 2024
1 parent e772909 commit ca3302d
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions zbus/src/connection/handshake/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,16 @@ impl Client {
#[instrument(skip(self))]
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
async fn send_zero_byte(&mut self) -> Result<()> {
let written = self
.common
.socket_mut()
.write_mut()
.send_zero_byte()
.await
.map_err(|e| {
Error::Handshake(format!("Could not send zero byte with credentials: {}", e))
})
.and_then(|n| match n {
None => Err(Error::Handshake(
"Could not send zero byte with credentials".to_string(),
)),
Some(n) => Ok(n),
})?;
let write = self.common.socket_mut().write_mut();

let written = match write.send_zero_byte().await.map_err(|e| {
Error::Handshake(format!("Could not send zero byte with credentials: {}", e))
})? {
// This likely means that the socket type is unable to send SCM_CREDS.
// Let's try to send the 0 byte as a regular message.
None => write.sendmsg(&[0], &[]).await?,
Some(n) => n,
};

if written != 1 {
return Err(Error::Handshake(
Expand Down

0 comments on commit ca3302d

Please sign in to comment.