Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💥 zb,zm: Drop Arc wrapping of Message everywhere #492

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zbus/src/blocking/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use enumflags2::BitFlags;
use event_listener::EventListener;
use static_assertions::assert_impl_all;
use std::{io, ops::Deref, sync::Arc};
use std::{io, ops::Deref};
use zbus_names::{BusName, ErrorName, InterfaceName, MemberName, OwnedUniqueName, WellKnownName};
use zvariant::ObjectPath;

Expand Down Expand Up @@ -84,7 +84,7 @@ impl Connection {
iface: Option<I>,
method_name: M,
body: &B,
) -> Result<Arc<Message>>
) -> Result<Message>
where
D: TryInto<BusName<'d>>,
P: TryInto<ObjectPath<'p>>,
Expand Down
3 changes: 1 addition & 2 deletions zbus/src/blocking/message_iterator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use futures_util::StreamExt;
use static_assertions::assert_impl_all;
use std::sync::Arc;

use crate::{
blocking::Connection, message::Message, utils::block_on, MatchRule, OwnedMatchRule, Result,
Expand Down Expand Up @@ -112,7 +111,7 @@ impl MessageIterator {
}

impl Iterator for MessageIterator {
type Item = Result<Arc<Message>>;
type Item = Result<Message>;

fn next(&mut self) -> Option<Self::Item> {
block_on(self.azync.as_mut().expect("Inner stream is `None`").next())
Expand Down
6 changes: 3 additions & 3 deletions zbus/src/blocking/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use enumflags2::BitFlags;
use futures_util::StreamExt;
use static_assertions::assert_impl_all;
use std::{ops::Deref, sync::Arc};
use std::ops::Deref;
use zbus_names::{BusName, InterfaceName, MemberName, UniqueName};
use zvariant::{ObjectPath, OwnedValue, Value};

Expand Down Expand Up @@ -207,7 +207,7 @@ impl<'a> Proxy<'a> {
/// allocation/copying, by deserializing the reply to an unowned type).
///
/// [`call`]: struct.Proxy.html#method.call
pub fn call_method<'m, M, B>(&self, method_name: M, body: &B) -> Result<Arc<Message>>
pub fn call_method<'m, M, B>(&self, method_name: M, body: &B) -> Result<Message>
where
M: TryInto<MemberName<'m>>,
M::Error: Into<Error>,
Expand Down Expand Up @@ -393,7 +393,7 @@ impl<'a> SignalIterator<'a> {
assert_impl_all!(SignalIterator<'_>: Send, Sync, Unpin);

impl std::iter::Iterator for SignalIterator<'_> {
type Item = Arc<Message>;
type Item = Message;

fn next(&mut self) -> Option<Self::Item> {
block_on(self.0.as_mut().expect("`SignalStream` is `None`").next())
Expand Down
16 changes: 8 additions & 8 deletions zbus/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ pub(crate) struct ConnectionInner {
#[allow(unused)]
socket_reader_task: OnceCell<Task<()>>,

pub(crate) msg_receiver: InactiveReceiver<Result<Arc<Message>>>,
pub(crate) method_return_receiver: InactiveReceiver<Result<Arc<Message>>>,
pub(crate) msg_receiver: InactiveReceiver<Result<Message>>,
pub(crate) method_return_receiver: InactiveReceiver<Result<Message>>,
msg_senders: Arc<Mutex<HashMap<Option<OwnedMatchRule>, MsgBroadcaster>>>,

subscriptions: Mutex<Subscriptions>,
Expand All @@ -76,9 +76,9 @@ pub(crate) struct ConnectionInner {
object_server_dispatch_task: OnceCell<Task<()>>,
}

type Subscriptions = HashMap<OwnedMatchRule, (u64, InactiveReceiver<Result<Arc<Message>>>)>;
type Subscriptions = HashMap<OwnedMatchRule, (u64, InactiveReceiver<Result<Message>>)>;

pub(crate) type MsgBroadcaster = Broadcaster<Result<Arc<Message>>>;
pub(crate) type MsgBroadcaster = Broadcaster<Result<Message>>;

/// A D-Bus connection.
///
Expand Down Expand Up @@ -206,7 +206,7 @@ pub(crate) struct PendingMethodCall {
}

impl Future for PendingMethodCall {
type Output = Result<Arc<Message>>;
type Output = Result<Message>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.poll_before(cx, None).map(|ret| {
Expand All @@ -220,7 +220,7 @@ impl Future for PendingMethodCall {
}

impl OrderedFuture for PendingMethodCall {
type Output = Result<Arc<Message>>;
type Output = Result<Message>;
type Ordering = zbus::message::Sequence;

fn poll_before(
Expand Down Expand Up @@ -311,7 +311,7 @@ impl Connection {
interface: Option<I>,
method_name: M,
body: &B,
) -> Result<Arc<Message>>
) -> Result<Message>
where
D: TryInto<BusName<'d>>,
P: TryInto<ObjectPath<'p>>,
Expand Down Expand Up @@ -1028,7 +1028,7 @@ impl Connection {
&self,
rule: OwnedMatchRule,
max_queued: Option<usize>,
) -> Result<Receiver<Result<Arc<Message>>>> {
) -> Result<Receiver<Result<Message>>> {
use std::collections::hash_map::Entry;

if self.inner.msg_senders.lock().await.is_empty() {
Expand Down
3 changes: 1 addition & 2 deletions zbus/src/connection/socket_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl SocketReader {
}

#[instrument]
async fn read_socket(&mut self) -> crate::Result<Arc<Message>> {
async fn read_socket(&mut self) -> crate::Result<Message> {
self.activity_event.notify(usize::MAX);
let mut bytes = self
.already_received_bytes
Expand Down Expand Up @@ -185,6 +185,5 @@ impl SocketReader {
fds,
seq,
)
.map(Arc::new)
}
}
8 changes: 1 addition & 7 deletions zbus/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum Error {
/// A D-Bus method error reply.
// According to the spec, there can be all kinds of details in D-Bus errors but nobody adds
// anything more than a string description.
MethodError(OwnedErrorName, Option<String>, Arc<Message>),
MethodError(OwnedErrorName, Option<String>, Message),
/// A required field is missing in the message headers.
MissingField,
/// Invalid D-Bus GUID.
Expand Down Expand Up @@ -226,12 +226,6 @@ impl From<Infallible> for Error {
// For messages that are D-Bus error returns
impl From<Message> for Error {
fn from(message: Message) -> Error {
Self::from(Arc::new(message))
}
}

impl From<Arc<Message>> for Error {
fn from(message: Arc<Message>) -> Error {
// FIXME: Instead of checking this, we should have Method as trait and specific types for
// each message type.
let header = message.header();
Expand Down
23 changes: 14 additions & 9 deletions zbus/src/message/builder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::io::{Cursor, Write};
use std::{
io::{Cursor, Write},
sync::Arc,
};

#[cfg(unix)]
use crate::message::Fds;
#[cfg(unix)]
use std::{os::unix::io::RawFd, sync::Arc};
use std::os::unix::io::RawFd;

use enumflags2::BitFlags;
use zbus_names::{BusName, ErrorName, InterfaceName, MemberName, UniqueName};
Expand Down Expand Up @@ -326,13 +329,15 @@ impl<'a> Builder<'a> {
let quick_fields = QuickFields::new(&bytes, &header)?;

Ok(Message {
primary_header,
quick_fields,
bytes,
body_offset,
#[cfg(unix)]
fds: Arc::new(Fds::Raw(fds)),
recv_seq: Sequence::default(),
inner: Arc::new(super::Inner {
primary_header,
quick_fields,
bytes,
body_offset,
#[cfg(unix)]
fds: Fds::Raw(fds),
recv_seq: Sequence::default(),
}),
})
}
}
Expand Down
Loading