1818 * along with rperf. If not, see <https://www.gnu.org/licenses/>.
1919 */
2020
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 } ;
2223use crate :: BoxResult ;
2324
24- use super :: { parse_port_spec, TestStream , INTERVAL } ;
25-
2625pub const TEST_HEADER_SIZE : usize = 16 ;
2726
2827#[ cfg( unix) ]
@@ -38,7 +37,7 @@ pub struct TcpTestDefinition {
3837 pub length : usize ,
3938}
4039impl TcpTestDefinition {
41- pub fn new ( details : & serde_json:: Value ) -> super :: BoxResult < TcpTestDefinition > {
40+ pub fn new ( details : & serde_json:: Value ) -> BoxResult < TcpTestDefinition > {
4241 let mut test_id_bytes = [ 0_u8 ; 16 ] ;
4342 for ( i, v) in details
4443 . get ( "test_id" )
@@ -76,13 +75,14 @@ impl TcpTestDefinition {
7675}
7776
7877pub mod receiver {
78+ use mio:: net:: { TcpListener , TcpStream } ;
7979 use std:: io:: Read ;
8080 use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr , SocketAddr } ;
8181 use std:: sync:: atomic:: { AtomicBool , Ordering :: Relaxed } ;
8282 use std:: sync:: Mutex ;
8383 use std:: time:: { Duration , Instant } ;
8484
85- use mio :: net :: { TcpListener , TcpStream } ;
85+ use crate :: { protocol :: results :: IntervalResultBox , BoxResult } ;
8686
8787 const POLL_TIMEOUT : Duration = Duration :: from_millis ( 250 ) ;
8888 const CONNECTION_TIMEOUT : Duration = Duration :: from_secs ( 1 ) ;
@@ -97,7 +97,7 @@ pub mod receiver {
9797 lock_ip6 : Mutex < u8 > ,
9898 }
9999 impl TcpPortPool {
100- pub fn new ( port_spec : String , port_spec6 : String ) -> TcpPortPool {
100+ pub fn new ( port_spec : & str , port_spec6 : & str ) -> TcpPortPool {
101101 let ports = super :: parse_port_spec ( port_spec) ;
102102 if !ports. is_empty ( ) {
103103 log:: debug!( "configured IPv4 TCP port pool: {:?}" , ports) ;
@@ -123,7 +123,7 @@ pub mod receiver {
123123 }
124124 }
125125
126- pub fn bind ( & mut self , peer_ip : & IpAddr ) -> super :: BoxResult < TcpListener > {
126+ pub fn bind ( & mut self , peer_ip : & IpAddr ) -> BoxResult < TcpListener > {
127127 match peer_ip {
128128 IpAddr :: V6 ( _) => {
129129 if self . ports_ip6 . is_empty ( ) {
@@ -193,7 +193,6 @@ pub mod receiver {
193193 }
194194 }
195195
196- #[ allow( dead_code) ]
197196 pub struct TcpReceiver {
198197 active : AtomicBool ,
199198 test_definition : super :: TcpTestDefinition ,
@@ -213,7 +212,7 @@ pub mod receiver {
213212 stream_idx : & u8 ,
214213 port_pool : & mut TcpPortPool ,
215214 peer_ip : & IpAddr ,
216- ) -> super :: BoxResult < TcpReceiver > {
215+ ) -> BoxResult < TcpReceiver > {
217216 log:: debug!( "binding TCP listener for stream {}..." , stream_idx) ;
218217 let mut listener: TcpListener = port_pool. bind ( peer_ip) . expect ( "failed to bind TCP socket" ) ;
219218 log:: debug!( "bound TCP listener for stream {}: {}" , stream_idx, listener. local_addr( ) ?) ;
@@ -238,7 +237,7 @@ pub mod receiver {
238237 } )
239238 }
240239
241- fn process_connection ( & mut self ) -> super :: BoxResult < ( TcpStream , u64 , f32 ) > {
240+ fn process_connection ( & mut self ) -> BoxResult < ( TcpStream , u64 , f32 ) > {
242241 log:: debug!( "preparing to receive TCP stream {} connection..." , self . stream_idx) ;
243242
244243 let listener = self . listener . as_mut ( ) . unwrap ( ) ;
@@ -357,7 +356,7 @@ pub mod receiver {
357356 }
358357
359358 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 > > {
361360 let mut bytes_received: u64 = 0 ;
362361
363362 let mut additional_time_elapsed: f32 = 0.0 ;
@@ -450,7 +449,7 @@ pub mod receiver {
450449 }
451450 }
452451
453- fn get_port ( & self ) -> super :: BoxResult < u16 > {
452+ fn get_port ( & self ) -> BoxResult < u16 > {
454453 match & self . listener {
455454 Some ( listener) => Ok ( listener. local_addr ( ) ?. port ( ) ) ,
456455 None => match & self . stream {
@@ -476,6 +475,8 @@ pub mod sender {
476475 use std:: thread:: sleep;
477476 use std:: time:: { Duration , Instant } ;
478477
478+ use crate :: { protocol:: results:: IntervalResultBox , BoxResult } ;
479+
479480 const CONNECT_TIMEOUT : Duration = Duration :: from_secs ( 2 ) ;
480481 const WRITE_TIMEOUT : Duration = Duration :: from_millis ( 50 ) ;
481482 const BUFFER_FULL_TIMEOUT : Duration = Duration :: from_millis ( 1 ) ;
@@ -509,7 +510,7 @@ pub mod sender {
509510 send_interval : & f32 ,
510511 send_buffer : & usize ,
511512 no_delay : & bool ,
512- ) -> super :: BoxResult < TcpSender > {
513+ ) -> BoxResult < TcpSender > {
513514 let mut staged_buffer = vec ! [ 0_u8 ; test_definition. length] ;
514515 for ( i, staged_buffer_i) in staged_buffer. iter_mut ( ) . enumerate ( ) . skip ( super :: TEST_HEADER_SIZE ) {
515516 //fill the packet with a fixed sequence
@@ -536,8 +537,8 @@ pub mod sender {
536537 } )
537538 }
538539
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 ) ;
541542
542543 let stream = match TcpStream :: connect_timeout ( & self . socket_addr , CONNECT_TIMEOUT ) {
543544 Ok ( s) => s,
@@ -575,7 +576,7 @@ pub mod sender {
575576 }
576577 }
577578 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 > > {
579580 if self . stream . is_none ( ) {
580581 //if still in the setup phase, connect to the receiver
581582 match self . process_connection ( ) {
@@ -704,7 +705,7 @@ pub mod sender {
704705 }
705706 }
706707
707- fn get_port ( & self ) -> super :: BoxResult < u16 > {
708+ fn get_port ( & self ) -> BoxResult < u16 > {
708709 match & self . stream {
709710 Some ( stream) => Ok ( stream. local_addr ( ) ?. port ( ) ) ,
710711 None => Err ( Box :: new ( simple_error:: simple_error!( "no stream currently exists" ) ) ) ,
0 commit comments