Skip to content

Commit

Permalink
Fix the bug of an async runtime demanded by UdpSocket::from_std
Browse files Browse the repository at this point in the history
  • Loading branch information
YuanYuYuan committed Mar 11, 2024
1 parent 6a139b1 commit 40a4e48
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions zenoh/src/net/runtime/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,11 @@ impl Runtime {
// Must set to nonblocking according to the doc of tokio
// https://docs.rs/tokio/latest/tokio/net/struct.UdpSocket.html#notes
socket.set_nonblocking(true)?;
Ok(UdpSocket::from_std(socket.into())?)

// UdpSocket::from_std requires a runtime even though it's a sync function
let udp_socket = zenoh_runtime::ZRuntime::Net
.block_in_place(async { UdpSocket::from_std(socket.into()) })?;
Ok(udp_socket)
}

pub fn bind_ucast_port(addr: IpAddr) -> ZResult<UdpSocket> {
Expand Down Expand Up @@ -453,7 +457,11 @@ impl Runtime {
// Must set to nonblocking according to the doc of tokio
// https://docs.rs/tokio/latest/tokio/net/struct.UdpSocket.html#notes
socket.set_nonblocking(true)?;
Ok(UdpSocket::from_std(socket.into())?)

// UdpSocket::from_std requires a runtime even though it's a sync function
let udp_socket = zenoh_runtime::ZRuntime::Net
.block_in_place(async { UdpSocket::from_std(socket.into()) })?;
Ok(udp_socket)
}

async fn spawn_peer_connector(&self, peer: EndPoint) -> ZResult<()> {
Expand Down

0 comments on commit 40a4e48

Please sign in to comment.