Skip to content

Commit

Permalink
Merge pull request #29 from windy1/release/0.11.1
Browse files Browse the repository at this point in the history
Release 0.11.1
  • Loading branch information
windy1 authored Aug 19, 2023
2 parents 14f2471 + 317f62e commit c0d3705
Show file tree
Hide file tree
Showing 27 changed files with 358 additions and 243 deletions.
7 changes: 7 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ubuntu:jammy

RUN apt-get update && apt-get install -y curl git

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y

RUN apt-get install -y xorg-dev libxcb-shape0-dev libxcb-xfixes0-dev clang avahi-daemon libavahi-client-dev
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
"build": {
"dockerfile": "Dockerfile"
}
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [master]
pull_request:
branches: [master]
branches: [master, release/**]

env:
CARGO_TERM_COLOR: always
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
**/target
.vscode
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'zeroconf'",
"cargo": {
"args": [
"test",
"--no-run",
"--lib",
"--package=zeroconf"
],
"filter": {
"name": "zeroconf",
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_LOG": "debug"
}
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"editor.formatOnSave": true,
"cSpell.words": [
"aprotocol",
"errno",
"strlst",
"userdata"
]
}
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion scripts/checkfmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@

set -e

find examples/browser/src examples/service/src zeroconf/src zeroconf-macros/src -type f -name *.rs -print0 | xargs -0 -n1 rustfmt --check --verbose
find \
examples/browser/src \
examples/service/src \
zeroconf/src \
zeroconf-macros/src \
-type f \
-name *.rs \
-print0 | xargs -0 -n1 rustfmt --check --verbose
10 changes: 8 additions & 2 deletions zeroconf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zeroconf"
version = "0.11.0"
version = "0.11.1"
authors = ["Walker Crouse <walkercrouse@hotmail.com>"]
edition = "2018"
description = "cross-platform library that wraps ZeroConf/mDNS implementations like Bonjour or Avahi"
Expand All @@ -9,7 +9,13 @@ homepage = "https://github.com/windy1/zeroconf-rs"
repository = "https://github.com/windy1/zeroconf-rs"
license-file = "../LICENSE"
keywords = ["zeroconf", "mdns", "avahi", "bonjour", "dnssd"]
categories = ["api-bindings", "network-programming", "os", "os::linux-apis", "os::macos-apis"]
categories = [
"api-bindings",
"network-programming",
"os",
"os::linux-apis",
"os::macos-apis",
]
documentation = "https://docs.rs/zeroconf"

[dependencies]
Expand Down
18 changes: 18 additions & 0 deletions zeroconf/src/linux/avahi_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ pub fn interface_index(interface: NetworkInterface) -> i32 {
}
}

/// Executes the specified closure and returns a formatted `Result`
pub fn sys_exec<F: FnOnce() -> i32>(func: F, message: &str) -> crate::Result<()> {
let err = func();

if err < 0 {
crate::Result::Err(
format!(
"{}: `{}`",
message,
crate::linux::avahi_util::get_error(err)
)
.into(),
)
} else {
crate::Result::Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 3 additions & 3 deletions zeroconf/src/linux/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl TMdnsBrowser for AvahiMdnsBrowser {

self.client = Some(Arc::new(ManagedAvahiClient::new(
ManagedAvahiClientParams::builder()
.poll(self.poll.as_ref().unwrap())
.poll(Arc::clone(self.poll.as_ref().unwrap()))
.flags(AvahiClientFlags(0))
.callback(Some(client_callback))
.userdata(ptr::null_mut())
Expand All @@ -91,7 +91,7 @@ impl TMdnsBrowser for AvahiMdnsBrowser {
.flags(0)
.callback(Some(browse_callback))
.userdata(self.context.as_raw())
.client(self.context.client.as_ref().unwrap())
.client(Arc::clone(self.context.client.as_ref().unwrap()))
.build()?,
)?);

Expand Down Expand Up @@ -182,7 +182,7 @@ fn handle_browser_new(
let raw_context = context.as_raw();
context.resolvers.insert(ManagedAvahiServiceResolver::new(
ManagedAvahiServiceResolverParams::builder()
.client(context.client.as_ref().unwrap())
.client(Arc::clone(context.client.as_ref().unwrap()))
.interface(interface)
.protocol(protocol)
.name(name)
Expand Down
25 changes: 13 additions & 12 deletions zeroconf/src/linux/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Rust friendly `AvahiClient` wrappers/helpers

use std::sync::Arc;

use super::avahi_util;
use super::poll::ManagedAvahiSimplePoll;
use crate::ffi::c_str;
Expand All @@ -15,7 +17,10 @@ use libc::{c_int, c_void};
/// This struct allocates a new `*mut AvahiClient` when `ManagedAvahiClient::new()` is invoked and
/// calls the Avahi function responsible for freeing the client on `trait Drop`.
#[derive(Debug)]
pub struct ManagedAvahiClient(*mut AvahiClient);
pub struct ManagedAvahiClient {
pub(crate) inner: *mut AvahiClient,
_poll: Arc<ManagedAvahiSimplePoll>,
}

impl ManagedAvahiClient {
/// Initializes the underlying `*mut AvahiClient` and verifies it was created; returning
Expand All @@ -30,7 +35,7 @@ impl ManagedAvahiClient {
) -> Result<Self> {
let mut err: c_int = 0;

let client = unsafe {
let inner = unsafe {
avahi_client_new(
avahi_simple_poll_get(poll.inner()),
flags,
Expand All @@ -40,12 +45,12 @@ impl ManagedAvahiClient {
)
};

if client.is_null() {
if inner.is_null() {
return Err("could not initialize AvahiClient".into());
}

match err {
0 => Ok(Self(client)),
0 => Ok(Self { inner, _poll: poll }),
_ => Err(format!(
"could not initialize AvahiClient: {}",
avahi_util::get_error(err)
Expand All @@ -58,17 +63,13 @@ impl ManagedAvahiClient {
///
/// [`avahi_client_get_host_name()`]: https://avahi.org/doxygen/html/client_8h.html#a89378618c3c592a255551c308ba300bf
pub fn host_name<'a>(&self) -> Result<&'a str> {
unsafe { get_host_name(self.0) }
}

pub(super) fn inner(&self) -> *mut AvahiClient {
self.0
unsafe { get_host_name(self.inner) }
}
}

impl Drop for ManagedAvahiClient {
fn drop(&mut self) {
unsafe { avahi_client_free(self.0) };
unsafe { avahi_client_free(self.inner) };
}
}

Expand All @@ -78,8 +79,8 @@ impl Drop for ManagedAvahiClient {
///
/// [`avahi_client_new()`]: https://avahi.org/doxygen/html/client_8h.html#a07b2a33a3e7cbb18a0eb9d00eade6ae6
#[derive(Builder, BuilderDelegate)]
pub struct ManagedAvahiClientParams<'a> {
poll: &'a ManagedAvahiSimplePoll,
pub struct ManagedAvahiClientParams {
poll: Arc<ManagedAvahiSimplePoll>,
flags: AvahiClientFlags,
callback: AvahiClientCallback,
userdata: *mut c_void,
Expand Down
Loading

0 comments on commit c0d3705

Please sign in to comment.