@@ -66,22 +66,23 @@ impl Endpoint<TcpStream> for TcpStream {
66
66
async fn copy < A : Endpoint < A > , B : Endpoint < B > > (
67
67
from : Rc < A > ,
68
68
to : Rc < B > ,
69
- dbg_name : & ' static str ,
69
+ dbg_name_from : & ' static str ,
70
+ dbg_name_to : & ' static str ,
70
71
bytes_written : Arc < AtomicUsize > ,
71
72
) -> Result < ( ) > {
72
73
let mut buf = vec ! [ 0u8 ; BUFFER_LEN ] ;
73
74
loop {
74
75
// things look weird: we pass ownership of the buffer to `read`, and we get
75
76
// it back, _even if there was an error_. There's a whole trait for that,
76
77
// which `Vec<u8>` implements!
77
- debug ! ( "{}: before read" , dbg_name ) ;
78
+ debug ! ( "{}: before read" , dbg_name_from ) ;
78
79
let retval = from. read ( buf) ;
79
80
let ( res, buf_read) = timeout ( READ_TIMEOUT , retval)
80
81
. await
81
- . map_err ( |e| -> String { format ! ( "{} read: {}" , dbg_name , e) } ) ?;
82
+ . map_err ( |e| -> String { format ! ( "{} read: {}" , dbg_name_from , e) } ) ?;
82
83
// Propagate errors, see how many bytes we read
83
84
let n = res?;
84
- debug ! ( "{}: after read, {} bytes" , dbg_name , n) ;
85
+ debug ! ( "{}: after read, {} bytes" , dbg_name_from , n) ;
85
86
if n == 0 {
86
87
// A read of size zero signals EOF (end of file), finish gracefully
87
88
return Ok ( ( ) ) ;
@@ -90,13 +91,13 @@ async fn copy<A: Endpoint<A>, B: Endpoint<B>>(
90
91
// The `slice` method here is implemented in an extension trait: it
91
92
// returns an owned slice of our `Vec<u8>`, which we later turn back
92
93
// into the full `Vec<u8>`
93
- debug ! ( "{}: before write" , dbg_name ) ;
94
+ debug ! ( "{}: before write" , dbg_name_to ) ;
94
95
let retval = to. write ( buf_read. slice ( ..n) ) . submit ( ) ;
95
96
let ( res, buf_write) = timeout ( READ_TIMEOUT , retval)
96
97
. await
97
- . map_err ( |e| -> String { format ! ( "{} write: {}" , dbg_name , e) } ) ?;
98
+ . map_err ( |e| -> String { format ! ( "{} write: {}" , dbg_name_to , e) } ) ?;
98
99
let n = res?;
99
- debug ! ( "{}: after write, {} bytes" , dbg_name , n) ;
100
+ debug ! ( "{}: after write, {} bytes" , dbg_name_to , n) ;
100
101
// Increment byte counters for statistics
101
102
bytes_written. fetch_add ( n, Ordering :: Relaxed ) ;
102
103
@@ -253,12 +254,14 @@ pub async fn io_loop(
253
254
file. clone ( ) ,
254
255
stream. clone ( ) ,
255
256
"USB" ,
257
+ "TCP" ,
256
258
stream_bytes. clone ( ) ,
257
259
) ) ;
258
260
let mut from_stream = tokio_uring:: spawn ( copy (
259
261
stream. clone ( ) ,
260
262
file. clone ( ) ,
261
263
"TCP" ,
264
+ "USB" ,
262
265
file_bytes. clone ( ) ,
263
266
) ) ;
264
267
0 commit comments