Skip to content

Commit 2df7e9c

Browse files
committed
Create PortUnregistrationError for port registration failures
1 parent 81658d7 commit 2df7e9c

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎src/client/client_impl.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,15 @@ impl Client {
564564
}
565565
}
566566

567+
/// Remove the port from the client, disconnecting any existing connections.
568+
///
569+
/// `Err(Error::PortUnregistrationError)` is returned on failure, for example if the port does
570+
/// not belong to this client.
567571
pub fn unregister_port<PS>(&self, port: Port<PS>) -> Result<(), Error> {
568572
let res = unsafe { j::jack_port_unregister(self.raw(), port.raw()) };
569573
match res {
570574
0 => Ok(()),
571-
_ => Err(Error::PortDisconnectionError),
575+
_ => Err(Error::PortUnregistrationError),
572576
}
573577
}
574578

‎src/jack_enums.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum Error {
2323
PortMonitorError,
2424
PortNamingError,
2525
PortRegistrationError(String),
26+
PortUnregistrationError,
2627
SetBufferSizeError,
2728
TimeError,
2829
WeakFunctionNotFound(&'static str),
@@ -68,6 +69,7 @@ impl std::fmt::Display for Error {
6869
Error::PortMonitorError => write!(f, "port monitoring error"),
6970
Error::PortNamingError => write!(f, "port naming error"),
7071
Error::PortRegistrationError(p) => write!(f, "failed to register port {p}"),
72+
Error::PortUnregistrationError => write!(f, "failed to unregister port"),
7173
Error::SetBufferSizeError => write!(
7274
f,
7375
"set buffer size error, setting buffer size is likely not supported"

‎src/tests/client.rs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,18 @@ fn nonexistant_uuid_to_client_name_returns_none() {
8686
assert_eq!(DEFAULT_TEST_CLIENT.name_by_uuid_str(&uuid_string), None);
8787
assert_eq!(DEFAULT_TEST_CLIENT.name_by_uuid(uuid), None);
8888
}
89+
90+
#[test]
91+
fn unregistering_another_clients_port_is_an_unregistration_error() {
92+
let (owner, _) = crate::Client::new("", crate::ClientOptions::default()).unwrap();
93+
let (other, _) = crate::Client::new("", crate::ClientOptions::default()).unwrap();
94+
let port = owner.register_port("p", crate::AudioIn::default()).unwrap();
95+
// Some servers only publish ports of active clients.
96+
let _owner = owner.activate_async((), ()).unwrap();
97+
std::thread::sleep(std::time::Duration::from_millis(100));
98+
let foreign = other.port_by_name(&port.name().unwrap()).unwrap();
99+
assert_eq!(
100+
other.unregister_port(foreign),
101+
Err(crate::Error::PortUnregistrationError)
102+
);
103+
}

0 commit comments

Comments
 (0)