Skip to content

Commit d139bc1

Browse files
committed
fix: binding to 0.0.0.0
1 parent 437d905 commit d139bc1

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

edge-nal-embassy/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.4.1] - 2024-01-05
9+
* Fix regression: ability to UDP/TCP bind to socket 0.0.0.0
10+
811
## [0.4.0] - 2024-01-02
912
* Proper TCP socket shutdown; Generic TCP timeout utils; built-in HTTP server timeouts; update docu (#34)
1013
* fix a typo (#44)

edge-nal-embassy/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "edge-nal-embassy"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
edition = "2021"
55
rust-version = "1.77"
66
description = "An implementation of edge-nal based on `embassy-net`"

edge-nal-embassy/src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use core::mem::MaybeUninit;
77
use core::net::SocketAddr;
88
use core::ptr::NonNull;
99

10-
use embassy_net::IpEndpoint;
10+
use embassy_net::{IpEndpoint, IpListenEndpoint};
1111

1212
pub use dns::*;
1313
pub use tcp::*;
@@ -72,3 +72,17 @@ pub(crate) fn to_net_socket(socket: IpEndpoint) -> SocketAddr {
7272
// socket.port,
7373
// )
7474
// }
75+
76+
pub(crate) fn to_emb_socket(socket: SocketAddr) -> IpEndpoint {
77+
IpEndpoint {
78+
addr: socket.ip().into(),
79+
port: socket.port(),
80+
}
81+
}
82+
83+
pub(crate) fn to_emb_bind_socket(socket: SocketAddr) -> IpListenEndpoint {
84+
IpListenEndpoint {
85+
addr: (!socket.ip().is_unspecified()).then(|| socket.ip().into()),
86+
port: socket.port(),
87+
}
88+
}

edge-nal-embassy/src/tcp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use embassy_net::Stack;
1111

1212
use embedded_io_async::{ErrorKind, ErrorType, Read, Write};
1313

14-
use crate::{to_net_socket, Pool};
14+
use crate::{to_emb_bind_socket, to_emb_socket, to_net_socket, Pool};
1515

1616
/// A struct that implements the `TcpConnect` and `TcpBind` factory traits from `edge-nal`
1717
/// Capable of managing up to N concurrent connections with TX and RX buffers according to TX_SZ and RX_SZ.
@@ -44,7 +44,7 @@ impl<const N: usize, const TX_SZ: usize, const RX_SZ: usize> TcpConnect
4444
async fn connect(&self, remote: SocketAddr) -> Result<Self::Socket<'_>, Self::Error> {
4545
let mut socket = TcpSocket::new(self.stack, self.buffers)?;
4646

47-
socket.socket.connect(remote).await?;
47+
socket.socket.connect(to_emb_socket(remote)).await?;
4848

4949
Ok(socket)
5050
}
@@ -82,7 +82,7 @@ impl<const N: usize, const TX_SZ: usize, const RX_SZ: usize> edge_nal::TcpAccept
8282
async fn accept(&self) -> Result<(SocketAddr, Self::Socket<'_>), Self::Error> {
8383
let mut socket = TcpSocket::new(self.stack.stack, self.stack.buffers)?;
8484

85-
socket.socket.accept(self.local).await?;
85+
socket.socket.accept(to_emb_bind_socket(self.local)).await?;
8686

8787
let local_endpoint = socket.socket.local_endpoint().unwrap();
8888

edge-nal-embassy/src/udp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use embassy_net::{MulticastError, Stack};
88

99
use embedded_io_async::{ErrorKind, ErrorType};
1010

11-
use crate::{to_net_socket, Pool};
11+
use crate::{to_emb_bind_socket, to_emb_socket, to_net_socket, Pool};
1212

1313
/// A struct that implements the `UdpBind` factory trait from `edge-nal`
1414
/// Capable of managing up to N concurrent connections with TX and RX buffers according to TX_SZ and RX_SZ, and packet metadata according to `M`.
@@ -49,7 +49,7 @@ impl<const N: usize, const TX_SZ: usize, const RX_SZ: usize, const M: usize> Udp
4949
async fn bind(&self, local: SocketAddr) -> Result<Self::Socket<'_>, Self::Error> {
5050
let mut socket = UdpSocket::new(self.stack, self.buffers)?;
5151

52-
socket.socket.bind(local)?;
52+
socket.socket.bind(to_emb_bind_socket(local))?;
5353

5454
Ok(socket)
5555
}
@@ -125,7 +125,7 @@ impl<const N: usize, const TX_SZ: usize, const RX_SZ: usize, const M: usize> Udp
125125
for UdpSocket<'_, N, TX_SZ, RX_SZ, M>
126126
{
127127
async fn send(&mut self, remote: SocketAddr, data: &[u8]) -> Result<(), Self::Error> {
128-
self.socket.send_to(data, remote).await?;
128+
self.socket.send_to(data, to_emb_socket(remote)).await?;
129129

130130
Ok(())
131131
}

0 commit comments

Comments
 (0)