@@ -22,46 +22,46 @@ use crate::{
22
22
23
23
pub async fn select_protocol < M : Message + Sync + Send > (
24
24
address : & str ,
25
- ) -> tokio :: io:: Result < Box < dyn AsyncMavConnection < M > + Sync + Send > > {
25
+ ) -> io:: Result < Box < dyn AsyncMavConnection < M > + Sync + Send > > {
26
26
let connection = if let Some ( address) = address. strip_prefix ( "udpin:" ) {
27
27
udpin ( address) . await
28
28
} else if let Some ( address) = address. strip_prefix ( "udpout:" ) {
29
29
udpout ( address) . await
30
30
} else if let Some ( address) = address. strip_prefix ( "udpbcast:" ) {
31
31
udpbcast ( address) . await
32
32
} else {
33
- Err ( tokio :: io:: Error :: new (
34
- tokio :: io:: ErrorKind :: AddrNotAvailable ,
33
+ Err ( io:: Error :: new (
34
+ io:: ErrorKind :: AddrNotAvailable ,
35
35
"Protocol unsupported" ,
36
36
) )
37
37
} ;
38
38
39
39
Ok ( Box :: new ( connection?) )
40
40
}
41
41
42
- pub async fn udpbcast < T : std:: net:: ToSocketAddrs > ( address : T ) -> tokio :: io:: Result < UdpConnection > {
42
+ pub async fn udpbcast < T : std:: net:: ToSocketAddrs > ( address : T ) -> io:: Result < AsyncUdpConnection > {
43
43
let addr = get_socket_addr ( address) ?;
44
44
let socket = UdpSocket :: bind ( "0.0.0.0:0" ) . await ?;
45
45
socket
46
46
. set_broadcast ( true )
47
47
. expect ( "Couldn't bind to broadcast address." ) ;
48
- UdpConnection :: new ( socket, false , Some ( addr) )
48
+ AsyncUdpConnection :: new ( socket, false , Some ( addr) )
49
49
}
50
50
51
- pub async fn udpout < T : std:: net:: ToSocketAddrs > ( address : T ) -> tokio :: io:: Result < UdpConnection > {
51
+ pub async fn udpout < T : std:: net:: ToSocketAddrs > ( address : T ) -> io:: Result < AsyncUdpConnection > {
52
52
let addr = get_socket_addr ( address) ?;
53
53
let socket = UdpSocket :: bind ( "0.0.0.0:0" ) . await ?;
54
- UdpConnection :: new ( socket, false , Some ( addr) )
54
+ AsyncUdpConnection :: new ( socket, false , Some ( addr) )
55
55
}
56
56
57
- pub async fn udpin < T : std:: net:: ToSocketAddrs > ( address : T ) -> tokio :: io:: Result < UdpConnection > {
57
+ pub async fn udpin < T : std:: net:: ToSocketAddrs > ( address : T ) -> io:: Result < AsyncUdpConnection > {
58
58
let addr = address
59
59
. to_socket_addrs ( )
60
60
. unwrap ( )
61
61
. next ( )
62
62
. expect ( "Invalid address" ) ;
63
63
let socket = UdpSocket :: bind ( addr) . await ?;
64
- UdpConnection :: new ( socket, true , None )
64
+ AsyncUdpConnection :: new ( socket, true , None )
65
65
}
66
66
67
67
struct UdpRead {
@@ -75,7 +75,7 @@ impl AsyncRead for UdpRead {
75
75
fn poll_read (
76
76
mut self : core:: pin:: Pin < & mut Self > ,
77
77
cx : & mut core:: task:: Context < ' _ > ,
78
- buf : & mut tokio :: io:: ReadBuf < ' _ > ,
78
+ buf : & mut io:: ReadBuf < ' _ > ,
79
79
) -> Poll < io:: Result < ( ) > > {
80
80
if self . buffer . is_empty ( ) {
81
81
let mut read_buffer = [ 0u8 ; MTU_SIZE ] ;
@@ -115,7 +115,7 @@ struct UdpWrite {
115
115
sequence : u8 ,
116
116
}
117
117
118
- pub struct UdpConnection {
118
+ pub struct AsyncUdpConnection {
119
119
reader : Mutex < AsyncPeekReader < UdpRead > > ,
120
120
writer : Mutex < UdpWrite > ,
121
121
protocol_version : MavlinkVersion ,
@@ -124,12 +124,12 @@ pub struct UdpConnection {
124
124
signing_data : Option < SigningData > ,
125
125
}
126
126
127
- impl UdpConnection {
127
+ impl AsyncUdpConnection {
128
128
fn new (
129
129
socket : UdpSocket ,
130
130
server : bool ,
131
131
dest : Option < std:: net:: SocketAddr > ,
132
- ) -> tokio :: io:: Result < Self > {
132
+ ) -> io:: Result < Self > {
133
133
let socket = Arc :: new ( socket) ;
134
134
Ok ( Self {
135
135
server,
@@ -151,7 +151,7 @@ impl UdpConnection {
151
151
}
152
152
153
153
#[ async_trait:: async_trait]
154
- impl < M : Message + Sync + Send > AsyncMavConnection < M > for UdpConnection {
154
+ impl < M : Message + Sync + Send > AsyncMavConnection < M > for AsyncUdpConnection {
155
155
async fn recv ( & self ) -> Result < ( MavHeader , M ) , crate :: error:: MessageReadError > {
156
156
let mut reader = self . reader . lock ( ) . await ;
157
157
@@ -238,7 +238,7 @@ impl<M: Message + Sync + Send> AsyncMavConnection<M> for UdpConnection {
238
238
#[ cfg( test) ]
239
239
mod tests {
240
240
use super :: * ;
241
- use tokio :: io:: AsyncReadExt ;
241
+ use io:: AsyncReadExt ;
242
242
243
243
#[ tokio:: test]
244
244
async fn test_datagram_buffering ( ) {
0 commit comments