File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66- Added ` Error::PortUnregistrationError ` .
77- ` Client::unregister_port ` now returns ` Err(Error::PortUnregistrationError) ` on failure instead
88 of ` Err(Error::PortDisconnectionError) ` .
9+ - ` Client::register_port ` with the ` Unowned ` spec now returns ` Err(Error::PortRegistrationError) ` .
10+ - ` Unowned::jack_buffer_size ` now returns ` 0 ` instead of panicking.
911
1012## 0.9.0
1113
Original file line number Diff line number Diff line change @@ -273,7 +273,7 @@ impl Client {
273273 /// Each port has a short name. The port's full name contains the name of the client
274274 /// concatenated with a colon (:) followed by its short name. `Port::name_size()` is the maximum
275275 /// length of the full name. Exceeding that will cause the port registration to fail and return
276- /// `Err(() )`.
276+ /// `Err(Error::PortRegistrationError )`.
277277 ///
278278 /// The `port_name` must be unique among all ports owned by this client. If the name is not
279279 /// unique, the registration will fail.
@@ -282,6 +282,10 @@ impl Client {
282282 port_name : & str ,
283283 port_spec : PS ,
284284 ) -> Result < Port < PS > , Error > {
285+ // A port needs a type. This rejects `Unowned`, which only describes existing ports.
286+ if port_spec. jack_port_type ( ) . is_empty ( ) {
287+ return Err ( Error :: PortRegistrationError ( port_name. to_string ( ) ) ) ;
288+ }
285289 let port_name_c = ffi:: CString :: new ( port_name) . unwrap ( ) ;
286290 let port_type_c = ffi:: CString :: new ( port_spec. jack_port_type ( ) ) . unwrap ( ) ;
287291 let port_flags = port_spec. jack_flags ( ) . bits ( ) ;
Original file line number Diff line number Diff line change @@ -343,23 +343,27 @@ impl<PS> Port<PS> {
343343
344344/// `PortSpec` for a port that holds has no readable or writeable data from JACK on the created
345345/// client. It can be used to connect ports or to obtain metadata.
346+ ///
347+ /// `Unowned` describes ports obtained with `Client::port_by_name` or `Client::port_by_id`. It
348+ /// cannot be used to register a port: `Client::register_port` returns
349+ /// `Err(Error::PortRegistrationError)`.
346350#[ derive( Debug , Default ) ]
347351pub struct Unowned ;
348352
349353unsafe impl PortSpec for Unowned {
350- /// Panics on call since the `Unowned` spec can't be used to create ports.
354+ /// Empty, since the `Unowned` spec can't be used to create ports.
351355 fn jack_port_type ( & self ) -> & str {
352356 ""
353357 }
354358
355- /// Panics on call since the `Unowned` spec can't be used to create ports.
359+ /// Empty, since the `Unowned` spec can't be used to create ports.
356360 fn jack_flags ( & self ) -> PortFlags {
357361 PortFlags :: empty ( )
358362 }
359363
360- /// Panics on call since the `Unowned` spec can't be used to create ports.
364+ /// Zero, since the `Unowned` spec can't be used to create ports.
361365 fn jack_buffer_size ( & self ) -> libc:: c_ulong {
362- unreachable ! ( )
366+ 0
363367 }
364368}
365369
Original file line number Diff line number Diff line change @@ -101,3 +101,12 @@ fn unregistering_another_clients_port_is_an_unregistration_error() {
101101 Err ( crate :: Error :: PortUnregistrationError )
102102 ) ;
103103}
104+
105+ #[ test]
106+ fn registering_an_unowned_port_is_an_error ( ) {
107+ let ( client, _) = crate :: Client :: new ( "" , crate :: ClientOptions :: default ( ) ) . unwrap ( ) ;
108+ assert_eq ! (
109+ client. register_port( "p" , crate :: Unowned ) . map( |_| ( ) ) ,
110+ Err ( crate :: Error :: PortRegistrationError ( "p" . to_string( ) ) )
111+ ) ;
112+ }
You can’t perform that action at this time.
0 commit comments