18
18
* along with rperf. If not, see <https://www.gnu.org/licenses/>.
19
19
*/
20
20
21
- use crate :: protocol:: results:: { get_unix_timestamp, IntervalResult , TcpReceiveResult , TcpSendResult } ;
21
+ use crate :: protocol:: results:: { get_unix_timestamp, TcpReceiveResult , TcpSendResult } ;
22
+ use crate :: stream:: { parse_port_spec, TestStream , INTERVAL } ;
22
23
use crate :: BoxResult ;
23
24
24
- use super :: { parse_port_spec, TestStream , INTERVAL } ;
25
-
26
25
pub const TEST_HEADER_SIZE : usize = 16 ;
27
26
28
27
#[ cfg( unix) ]
@@ -38,7 +37,7 @@ pub struct TcpTestDefinition {
38
37
pub length : usize ,
39
38
}
40
39
impl TcpTestDefinition {
41
- pub fn new ( details : & serde_json:: Value ) -> super :: BoxResult < TcpTestDefinition > {
40
+ pub fn new ( details : & serde_json:: Value ) -> BoxResult < TcpTestDefinition > {
42
41
let mut test_id_bytes = [ 0_u8 ; 16 ] ;
43
42
for ( i, v) in details
44
43
. get ( "test_id" )
@@ -76,13 +75,14 @@ impl TcpTestDefinition {
76
75
}
77
76
78
77
pub mod receiver {
78
+ use mio:: net:: { TcpListener , TcpStream } ;
79
79
use std:: io:: Read ;
80
80
use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr , SocketAddr } ;
81
81
use std:: sync:: atomic:: { AtomicBool , Ordering :: Relaxed } ;
82
82
use std:: sync:: Mutex ;
83
83
use std:: time:: { Duration , Instant } ;
84
84
85
- use mio :: net :: { TcpListener , TcpStream } ;
85
+ use crate :: { protocol :: results :: IntervalResultBox , BoxResult } ;
86
86
87
87
const POLL_TIMEOUT : Duration = Duration :: from_millis ( 250 ) ;
88
88
const CONNECTION_TIMEOUT : Duration = Duration :: from_secs ( 1 ) ;
@@ -97,7 +97,7 @@ pub mod receiver {
97
97
lock_ip6 : Mutex < u8 > ,
98
98
}
99
99
impl TcpPortPool {
100
- pub fn new ( port_spec : String , port_spec6 : String ) -> TcpPortPool {
100
+ pub fn new ( port_spec : & str , port_spec6 : & str ) -> TcpPortPool {
101
101
let ports = super :: parse_port_spec ( port_spec) ;
102
102
if !ports. is_empty ( ) {
103
103
log:: debug!( "configured IPv4 TCP port pool: {:?}" , ports) ;
@@ -123,7 +123,7 @@ pub mod receiver {
123
123
}
124
124
}
125
125
126
- pub fn bind ( & mut self , peer_ip : & IpAddr ) -> super :: BoxResult < TcpListener > {
126
+ pub fn bind ( & mut self , peer_ip : & IpAddr ) -> BoxResult < TcpListener > {
127
127
match peer_ip {
128
128
IpAddr :: V6 ( _) => {
129
129
if self . ports_ip6 . is_empty ( ) {
@@ -193,7 +193,6 @@ pub mod receiver {
193
193
}
194
194
}
195
195
196
- #[ allow( dead_code) ]
197
196
pub struct TcpReceiver {
198
197
active : AtomicBool ,
199
198
test_definition : super :: TcpTestDefinition ,
@@ -213,7 +212,7 @@ pub mod receiver {
213
212
stream_idx : & u8 ,
214
213
port_pool : & mut TcpPortPool ,
215
214
peer_ip : & IpAddr ,
216
- ) -> super :: BoxResult < TcpReceiver > {
215
+ ) -> BoxResult < TcpReceiver > {
217
216
log:: debug!( "binding TCP listener for stream {}..." , stream_idx) ;
218
217
let mut listener: TcpListener = port_pool. bind ( peer_ip) . expect ( "failed to bind TCP socket" ) ;
219
218
log:: debug!( "bound TCP listener for stream {}: {}" , stream_idx, listener. local_addr( ) ?) ;
@@ -238,7 +237,7 @@ pub mod receiver {
238
237
} )
239
238
}
240
239
241
- fn process_connection ( & mut self ) -> super :: BoxResult < ( TcpStream , u64 , f32 ) > {
240
+ fn process_connection ( & mut self ) -> BoxResult < ( TcpStream , u64 , f32 ) > {
242
241
log:: debug!( "preparing to receive TCP stream {} connection..." , self . stream_idx) ;
243
242
244
243
let listener = self . listener . as_mut ( ) . unwrap ( ) ;
@@ -357,7 +356,7 @@ pub mod receiver {
357
356
}
358
357
359
358
impl super :: TestStream for TcpReceiver {
360
- fn run_interval ( & mut self ) -> Option < super :: BoxResult < Box < dyn super :: IntervalResult + Sync + Send > > > {
359
+ fn run_interval ( & mut self ) -> Option < BoxResult < IntervalResultBox > > {
361
360
let mut bytes_received: u64 = 0 ;
362
361
363
362
let mut additional_time_elapsed: f32 = 0.0 ;
@@ -450,7 +449,7 @@ pub mod receiver {
450
449
}
451
450
}
452
451
453
- fn get_port ( & self ) -> super :: BoxResult < u16 > {
452
+ fn get_port ( & self ) -> BoxResult < u16 > {
454
453
match & self . listener {
455
454
Some ( listener) => Ok ( listener. local_addr ( ) ?. port ( ) ) ,
456
455
None => match & self . stream {
@@ -476,6 +475,8 @@ pub mod sender {
476
475
use std:: thread:: sleep;
477
476
use std:: time:: { Duration , Instant } ;
478
477
478
+ use crate :: { protocol:: results:: IntervalResultBox , BoxResult } ;
479
+
479
480
const CONNECT_TIMEOUT : Duration = Duration :: from_secs ( 2 ) ;
480
481
const WRITE_TIMEOUT : Duration = Duration :: from_millis ( 50 ) ;
481
482
const BUFFER_FULL_TIMEOUT : Duration = Duration :: from_millis ( 1 ) ;
@@ -509,7 +510,7 @@ pub mod sender {
509
510
send_interval : & f32 ,
510
511
send_buffer : & usize ,
511
512
no_delay : & bool ,
512
- ) -> super :: BoxResult < TcpSender > {
513
+ ) -> BoxResult < TcpSender > {
513
514
let mut staged_buffer = vec ! [ 0_u8 ; test_definition. length] ;
514
515
for ( i, staged_buffer_i) in staged_buffer. iter_mut ( ) . enumerate ( ) . skip ( super :: TEST_HEADER_SIZE ) {
515
516
//fill the packet with a fixed sequence
@@ -536,8 +537,8 @@ pub mod sender {
536
537
} )
537
538
}
538
539
539
- fn process_connection ( & mut self ) -> super :: BoxResult < TcpStream > {
540
- log:: debug!( "preparing to connect TCP stream {}..." , self . stream_idx) ;
540
+ fn process_connection ( & mut self ) -> BoxResult < TcpStream > {
541
+ log:: debug!( "preparing to connect TCP stream {} to {} ..." , self . stream_idx, self . socket_addr ) ;
541
542
542
543
let stream = match TcpStream :: connect_timeout ( & self . socket_addr , CONNECT_TIMEOUT ) {
543
544
Ok ( s) => s,
@@ -575,7 +576,7 @@ pub mod sender {
575
576
}
576
577
}
577
578
impl super :: TestStream for TcpSender {
578
- fn run_interval ( & mut self ) -> Option < super :: BoxResult < Box < dyn super :: IntervalResult + Sync + Send > > > {
579
+ fn run_interval ( & mut self ) -> Option < BoxResult < IntervalResultBox > > {
579
580
if self . stream . is_none ( ) {
580
581
//if still in the setup phase, connect to the receiver
581
582
match self . process_connection ( ) {
@@ -704,7 +705,7 @@ pub mod sender {
704
705
}
705
706
}
706
707
707
- fn get_port ( & self ) -> super :: BoxResult < u16 > {
708
+ fn get_port ( & self ) -> BoxResult < u16 > {
708
709
match & self . stream {
709
710
Some ( stream) => Ok ( stream. local_addr ( ) ?. port ( ) ) ,
710
711
None => Err ( Box :: new ( simple_error:: simple_error!( "no stream currently exists" ) ) ) ,
0 commit comments