File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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"
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments