Skip to content

Commit

Permalink
dont panic during init
Browse files Browse the repository at this point in the history
Signed-off-by: Walker Crouse <walker.crouse@acuitybrands.com>
  • Loading branch information
Walker Crouse committed Jan 28, 2024
1 parent bc05415 commit ad5e519
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 5 additions & 2 deletions zeroconf/src/avahi/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ unsafe extern "C" fn client_callback(
let context = AvahiBrowserContext::from_raw(userdata);

match state {
avahi_sys::AvahiClientState_AVAHI_CLIENT_S_RUNNING => create_browser(client, context)
.unwrap_or_else(|e| panic!("failed to create browser: {}", e)),
avahi_sys::AvahiClientState_AVAHI_CLIENT_S_RUNNING => {
if let Err(e) = create_browser(client, context) {
context.invoke_callback(Err(e));
}
}
avahi_sys::AvahiClientState_AVAHI_CLIENT_FAILURE => {
context.invoke_callback(Err(avahi_util::get_last_error(client).into()))
}
Expand Down
11 changes: 8 additions & 3 deletions zeroconf/src/avahi/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,14 @@ unsafe extern "C" fn client_callback(
let context = AvahiServiceContext::from_raw(userdata);

match state {
avahi_sys::AvahiClientState_AVAHI_CLIENT_S_RUNNING => create_service(client, context)
.unwrap_or_else(|e| panic!("failed to create service: {}", e)),
avahi_sys::AvahiClientState_AVAHI_CLIENT_FAILURE => {
avahi_sys::AvahiServerState_AVAHI_SERVER_RUNNING => {
if let Err(e) = create_service(client, context) {
context.invoke_callback(Err(e))
}
}
avahi_sys::AvahiServerState_AVAHI_SERVER_INVALID
| avahi_sys::AvahiServerState_AVAHI_SERVER_COLLISION
| avahi_sys::AvahiServerState_AVAHI_SERVER_FAILURE => {
context.invoke_callback(Err(avahi_util::get_last_error(client).into()))
}
_ => {}
Expand Down

0 comments on commit ad5e519

Please sign in to comment.