14
14
//! Implementing `UniquelyBound` and `MultiplyBound` with the same type is expected to be a
15
15
//! common choice.
16
16
17
- use core:: future:: Future ;
18
17
use no_std_net:: SocketAddr ;
19
18
20
19
/// This trait is implemented by UDP sockets.
@@ -32,11 +31,7 @@ pub trait ConnectedUdp {
32
31
type Error : embedded_io:: Error ;
33
32
34
33
/// Send the provided data to the connected peer
35
- fn send < ' a > ( & ' a mut self , data : & ' a [ u8 ] ) -> Self :: SendFuture < ' a > ;
36
- /// Return type of the [`.send()`] method
37
- type SendFuture < ' a > : Future < Output = Result < ( ) , Self :: Error > >
38
- where
39
- Self : ' a ;
34
+ async fn send < ' a > ( & mut self , data : & [ u8 ] ) -> Result < ( ) , Self :: Error > ;
40
35
41
36
/// Receive a datagram into the provided buffer.
42
37
///
@@ -49,20 +44,16 @@ pub trait ConnectedUdp {
49
44
/// This deviates from the sync/nb equivalent trait in that it describes the overflow behavior
50
45
/// (a possibility not considered there). The name deviates from the original `receive()` to
51
46
/// make room for a version that is more zero-copy friendly.
52
- fn receive_into < ' a > ( & ' a mut self , buffer : & ' a mut [ u8 ] ) -> Self :: ReceiveIntoFuture < ' a > ;
53
- /// Return type of the [`.receive_into()`] method
54
- type ReceiveIntoFuture < ' a > : Future < Output = Result < usize , Self :: Error > >
55
- where
56
- Self : ' a ;
47
+ async fn receive_into ( & mut self , buffer : & mut [ u8 ] ) -> Result < usize , Self :: Error > ;
57
48
58
49
// WIP to allow zero-copy operation
59
50
// The plain receive is simple and can be provided -- implementations that don't populate
60
51
// receive calls from scatter-gather can just return a slice of the raw data instead, and rely
61
52
// on the socket still being exclusively owned. receive_oned is harder as providing it requires
62
53
// alloc.
63
54
//
64
- // fn receive(&mut self, buffer: &mut [u8]) -> impl Future<Output = Result<impl AsRef<u8> + '_, Self::Error> >;
65
- // fn receive_owned(&mut self) -> impl Future<Output = Result<impl AsRef<u8> + 'static, Self::Error> >;
55
+ // async fn receive(&mut self, buffer: &mut [u8]) -> utput = Result<impl AsRef<u8> + '_, Self::Error>;
56
+ // async fn receive_owned(&mut self) -> Result<impl AsRef<u8> + 'static, Self::Error>;
66
57
}
67
58
68
59
/// This trait is implemented by UDP sockets.
@@ -101,16 +92,12 @@ pub trait UnconnectedUdp {
101
92
/// receive time; these should be equal. This allows implementations of the trait to use a
102
93
/// single kind of socket for both sockets bound to a single and sockets bound to multiple
103
94
/// addresses.
104
- fn send < ' a > (
105
- & ' a mut self ,
95
+ async fn send (
96
+ & mut self ,
106
97
local : SocketAddr ,
107
98
remote : SocketAddr ,
108
- data : & ' a [ u8 ] ,
109
- ) -> Self :: SendFuture < ' a > ;
110
- /// Return type of the [`.send()`] method
111
- type SendFuture < ' a > : Future < Output = Result < ( ) , Self :: Error > >
112
- where
113
- Self : ' a ;
99
+ data : & [ u8 ] ,
100
+ ) -> Result < ( ) , Self :: Error > ;
114
101
115
102
/// Receive a datagram into the provided buffer.
116
103
///
@@ -120,12 +107,7 @@ pub trait UnconnectedUdp {
120
107
///
121
108
/// The local and remote address are given, in that order, in the result along with the number
122
109
/// of bytes.
123
- fn receive_into < ' a > ( & ' a mut self , buffer : & ' a mut [ u8 ] ) -> Self :: ReceiveIntoFuture < ' a > ;
124
- /// Return type of the [`.receive_into()`] method
125
- type ReceiveIntoFuture < ' a > : Future <
126
- Output = Result < ( usize , SocketAddr , SocketAddr ) , Self :: Error > ,
127
- > where
128
- Self : ' a ;
110
+ async fn receive_into ( & mut self , buffer : & mut [ u8 ] ) -> Result < ( usize , SocketAddr , SocketAddr ) , Self :: Error > ;
129
111
}
130
112
131
113
/// This trait is implemented by UDP/IP stacks. The trait allows the underlying driver to
@@ -138,17 +120,11 @@ pub trait UdpStack {
138
120
type Error : embedded_io:: Error ;
139
121
140
122
/// Eventual socket return type of the [`.connect()`] method
141
- type Connected < ' m > : ConnectedUdp
142
- where
143
- Self : ' m ;
123
+ type Connected : ConnectedUdp ;
144
124
/// Eventual socket return type of the [`.bind_single()`] method
145
- type UniquelyBound < ' m > : UnconnectedUdp
146
- where
147
- Self : ' m ;
125
+ type UniquelyBound : UnconnectedUdp ;
148
126
/// Eventual return type of the [`.bind_multiple()`] method
149
- type MultiplyBound < ' m > : UnconnectedUdp
150
- where
151
- Self : ' m ;
127
+ type MultiplyBound : UnconnectedUdp ;
152
128
153
129
/// Create a socket that has a fixed remote address.
154
130
///
@@ -157,34 +133,25 @@ pub trait UdpStack {
157
133
/// While asynchronous traits implemented through GAT can not have provided default methods,
158
134
/// implementers are encouraged to use the hidden `.connect_default()` method if all they would
159
135
/// do is delegating to [`.connect_from`] with a suitable unspecified local address.
160
- fn connect ( & self , remote : SocketAddr ) -> Self :: ConnectFuture < ' _ > ;
161
- /// Future return type of the [`.connect()`] method
162
- type ConnectFuture < ' a > : Future < Output = Result < ( SocketAddr , Self :: Connected < ' a > ) , Self :: Error > >
163
- where
164
- Self : ' a ;
136
+ async fn connect ( & self , remote : SocketAddr ) -> Result < ( SocketAddr , Self :: Connected ) , Self :: Error > ;
165
137
166
138
/// Create a socket that has a fixed remote address.
167
139
///
168
140
/// The local address is given explicitly, but may be partially unspecified; it is fixed by the
169
141
/// network stack at connection time. The full local address is returned along with the
170
142
/// connected socket, primarily for debugging purposes.
171
- fn connect_from ( & self , local : SocketAddr , remote : SocketAddr ) -> Self :: ConnectFromFuture < ' _ > ;
172
- /// Future return type of the [`.connect_from()`] method
173
- type ConnectFromFuture < ' a > : Future <
174
- Output = Result < ( SocketAddr , Self :: Connected < ' a > ) , Self :: Error > ,
175
- > where
176
- Self : ' a ;
143
+ async fn connect_from ( & self , local : SocketAddr , remote : SocketAddr ) -> Result < ( SocketAddr , Self :: Connected ) , Self :: Error > ;
177
144
178
145
/// Helper that implements [`connect()`] using [`connect_from()`].
179
146
#[ doc( hidden) ]
180
- fn connect_default ( & self , remote : SocketAddr ) -> Self :: ConnectFromFuture < ' _ > {
147
+ async fn connect_default ( & self , remote : SocketAddr ) -> Result < ( SocketAddr , Self :: Connected ) , Self :: Error > {
181
148
use no_std_net:: { Ipv4Addr , Ipv6Addr , SocketAddr :: * , SocketAddrV4 , SocketAddrV6 } ;
182
149
183
150
let local = match remote {
184
151
V4 ( _) => V4 ( SocketAddrV4 :: new ( Ipv4Addr :: UNSPECIFIED , 0 ) ) ,
185
152
V6 ( _) => V6 ( SocketAddrV6 :: new ( Ipv6Addr :: UNSPECIFIED , 0 , 0 , 0 ) ) ,
186
153
} ;
187
- self . connect_from ( local, remote)
154
+ self . connect_from ( local, remote) . await
188
155
}
189
156
190
157
/// Create a socket that has a fixed local address.
@@ -195,12 +162,7 @@ pub trait UdpStack {
195
162
///
196
163
/// The full local address is returned along with the bound socket; it may then be passed on to
197
164
/// other protocols for advertising purposes.
198
- fn bind_single ( & self , local : SocketAddr ) -> Self :: BindSingleFuture < ' _ > ;
199
- /// Future return type of the [`.bind_single()`] method
200
- type BindSingleFuture < ' a > : Future <
201
- Output = Result < ( SocketAddr , Self :: UniquelyBound < ' a > ) , Self :: Error > ,
202
- > where
203
- Self : ' a ;
165
+ async fn bind_single ( & self , local : SocketAddr ) -> Result < ( SocketAddr , Self :: UniquelyBound ) , Self :: Error > ;
204
166
205
167
/// Create a socket that has no single fixed local address.
206
168
///
@@ -224,9 +186,6 @@ pub trait UdpStack {
224
186
/// * There is currently no hybrid binding that allows emulating what POSIX systems do when
225
187
/// binding to `[::]:0`, that is, picking some available port but then still leaving the
226
188
/// interface and IP address unspecified.
227
- fn bind_multiple ( & self , local : SocketAddr ) -> Self :: BindMultipleFuture < ' _ > ;
228
- /// Future return type of the [`.bind_multiple()`] method
229
- type BindMultipleFuture < ' a > : Future < Output = Result < Self :: MultiplyBound < ' a > , Self :: Error > >
230
- where
231
- Self : ' a ;
189
+ async fn bind_multiple ( & self , local : SocketAddr ) -> Result < Self :: MultiplyBound , Self :: Error > ;
190
+
232
191
}
0 commit comments