mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-01-10 19:25:26 +00:00
threadshare: Update from the deprecated net2 to the socket2 crate
This commit is contained in:
parent
2e283b855a
commit
08da51744b
3 changed files with 35 additions and 18 deletions
|
@ -26,11 +26,14 @@ tokio = { git = "https://github.com/fengalin/tokio", branch = "fengalin/throttli
|
||||||
futures = { version = "0.3", features = ["thread-pool"] }
|
futures = { version = "0.3", features = ["thread-pool"] }
|
||||||
lazy_static = "1.0"
|
lazy_static = "1.0"
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
net2 = "0.2"
|
socket2 = "0.3"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["winsock2", "processthreadsapi"] }
|
winapi = { version = "0.3", features = ["winsock2", "processthreadsapi"] }
|
||||||
|
|
||||||
|
[target.'cfg(unix)'.dependencies]
|
||||||
|
socket2 = { version = "0.3", features = ["reuseport"] }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "gstthreadshare"
|
name = "gstthreadshare"
|
||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
|
@ -1003,18 +1003,26 @@ impl UdpSink {
|
||||||
let saddr = SocketAddr::new(bind_addr, bind_port as u16);
|
let saddr = SocketAddr::new(bind_addr, bind_port as u16);
|
||||||
gst_debug!(CAT, obj: element, "Binding to {:?}", saddr);
|
gst_debug!(CAT, obj: element, "Binding to {:?}", saddr);
|
||||||
|
|
||||||
let builder = match family {
|
let socket = match family {
|
||||||
SocketFamily::Ipv4 => net2::UdpBuilder::new_v4(),
|
SocketFamily::Ipv4 => socket2::Socket::new(
|
||||||
SocketFamily::Ipv6 => net2::UdpBuilder::new_v6(),
|
socket2::Domain::ipv4(),
|
||||||
|
socket2::Type::dgram(),
|
||||||
|
Some(socket2::Protocol::udp()),
|
||||||
|
),
|
||||||
|
SocketFamily::Ipv6 => socket2::Socket::new(
|
||||||
|
socket2::Domain::ipv6(),
|
||||||
|
socket2::Type::dgram(),
|
||||||
|
Some(socket2::Protocol::udp()),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let builder = match builder {
|
let socket = match socket {
|
||||||
Ok(builder) => builder,
|
Ok(socket) => socket,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
gst_warning!(
|
gst_warning!(
|
||||||
CAT,
|
CAT,
|
||||||
obj: element,
|
obj: element,
|
||||||
"Failed to create {} socket builder: {}",
|
"Failed to create {} socket: {}",
|
||||||
match family {
|
match family {
|
||||||
SocketFamily::Ipv4 => "IPv4",
|
SocketFamily::Ipv4 => "IPv4",
|
||||||
SocketFamily::Ipv6 => "IPv6",
|
SocketFamily::Ipv6 => "IPv6",
|
||||||
|
@ -1025,7 +1033,7 @@ impl UdpSink {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let socket = builder.bind(&saddr).map_err(|err| {
|
socket.bind(&saddr.into()).map_err(|err| {
|
||||||
gst_error_msg!(
|
gst_error_msg!(
|
||||||
gst::ResourceError::OpenWrite,
|
gst::ResourceError::OpenWrite,
|
||||||
["Failed to bind socket: {}", err]
|
["Failed to bind socket: {}", err]
|
||||||
|
@ -1033,7 +1041,7 @@ impl UdpSink {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let socket = context.enter(|| {
|
let socket = context.enter(|| {
|
||||||
tokio::net::UdpSocket::from_std(socket).map_err(|err| {
|
tokio::net::UdpSocket::from_std(socket.into()).map_err(|err| {
|
||||||
gst_error_msg!(
|
gst_error_msg!(
|
||||||
gst::ResourceError::OpenWrite,
|
gst::ResourceError::OpenWrite,
|
||||||
["Failed to setup socket for tokio: {}", err]
|
["Failed to setup socket for tokio: {}", err]
|
||||||
|
|
|
@ -618,10 +618,18 @@ impl UdpSrc {
|
||||||
saddr
|
saddr
|
||||||
};
|
};
|
||||||
|
|
||||||
let builder = if addr.is_ipv4() {
|
let socket = if addr.is_ipv4() {
|
||||||
net2::UdpBuilder::new_v4()
|
socket2::Socket::new(
|
||||||
|
socket2::Domain::ipv4(),
|
||||||
|
socket2::Type::dgram(),
|
||||||
|
Some(socket2::Protocol::udp()),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
net2::UdpBuilder::new_v6()
|
socket2::Socket::new(
|
||||||
|
socket2::Domain::ipv6(),
|
||||||
|
socket2::Type::dgram(),
|
||||||
|
Some(socket2::Protocol::udp()),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
gst_error_msg!(
|
gst_error_msg!(
|
||||||
|
@ -630,7 +638,7 @@ impl UdpSrc {
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
builder.reuse_address(settings.reuse).map_err(|err| {
|
socket.set_reuse_address(settings.reuse).map_err(|err| {
|
||||||
gst_error_msg!(
|
gst_error_msg!(
|
||||||
gst::ResourceError::OpenRead,
|
gst::ResourceError::OpenRead,
|
||||||
["Failed to set reuse_address: {}", err]
|
["Failed to set reuse_address: {}", err]
|
||||||
|
@ -639,9 +647,7 @@ impl UdpSrc {
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
use net2::unix::UnixUdpBuilderExt;
|
socket.set_reuse_port(settings.reuse).map_err(|err| {
|
||||||
|
|
||||||
builder.reuse_port(settings.reuse).map_err(|err| {
|
|
||||||
gst_error_msg!(
|
gst_error_msg!(
|
||||||
gst::ResourceError::OpenRead,
|
gst::ResourceError::OpenRead,
|
||||||
["Failed to set reuse_port: {}", err]
|
["Failed to set reuse_port: {}", err]
|
||||||
|
@ -649,7 +655,7 @@ impl UdpSrc {
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let socket = builder.bind(&saddr).map_err(|err| {
|
socket.bind(&saddr.into()).map_err(|err| {
|
||||||
gst_error_msg!(
|
gst_error_msg!(
|
||||||
gst::ResourceError::OpenRead,
|
gst::ResourceError::OpenRead,
|
||||||
["Failed to bind socket: {}", err]
|
["Failed to bind socket: {}", err]
|
||||||
|
@ -657,7 +663,7 @@ impl UdpSrc {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let socket = context.enter(|| {
|
let socket = context.enter(|| {
|
||||||
tokio::net::UdpSocket::from_std(socket).map_err(|err| {
|
tokio::net::UdpSocket::from_std(socket.into()).map_err(|err| {
|
||||||
gst_error_msg!(
|
gst_error_msg!(
|
||||||
gst::ResourceError::OpenRead,
|
gst::ResourceError::OpenRead,
|
||||||
["Failed to setup socket for tokio: {}", err]
|
["Failed to setup socket for tokio: {}", err]
|
||||||
|
|
Loading…
Reference in a new issue